Hiển thị các bài đăng có nhãn Linux. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Linux. Hiển thị tất cả bài đăng

Thứ Tư, 26 tháng 11, 2014

What happened if GCC search for libraries in C/C++

Hi all,
In some beautiful days, we wonder how GCC search for standard libraries like libstdc++.so. Cool! It really matters for those guys who works on developments of new standard libraries. They want to have both versions of libraries at the same time. It is a controversial topics. After I googled it, here is the summary I found.

There are two definitions denoted as ld you need to differentiate: linker in GCC and loader in linux. ld can refer to ld (GNU linker) (at compiling time). It can also refer to loader ld.so in linux (at running time).

How to know search path during linking and running time? 

During linking of GCC, we can use this instruction:
1/ You can do this by executing the following command:
ld --verbose | grep SEARCH_DIR | tr -s ' ;' \\012

2/ gcc passes a few extra -L paths to the linker, which you can list with the following command:
gcc -print-search-dirs | sed '/^lib/b 1;d;:1;s,/[^/.][^/]*/\.\./,/,;t 1;s,:[^=]*=,:;,;s,;,;  ,g' | tr \; \\012

The answers suggesting to use ld.so.conf and ldconfig are not correct because they refer to the paths searched by the runtime dynamic linker (i.e. whenever a program is executed), which is not the same as the path searched by ld (i.e. whenever a program is linked).

The most important keynote: GCC search -L paths first, then the default library (i.e, 2 first, then 1).

During run-time:
ldconfig -v 2>/dev/null | grep -v ^$'\t'

Thứ Sáu, 28 tháng 2, 2014

HOW-TO: build OpenCV 2.0 on Ubuntu 64 bits 12.04 LT

Hi all,
Sometimes, you want to build an old version of OpenCV on Ubuntu 64 bits. It seems not to be easy as I think. I met this error. That was suck.

../include/opencv/cxoperations.hpp:1916:15: error: ‘ptrdiff_t’ does not name a type
../include/opencv/cxoperations.hpp:2465:31: error: ‘ptrdiff_t’ does not name a type
The reason is that library might lack of a header file [1]. Just add "#include <cstddef>" to corresponding headers file that generates errors including cxoperations.hpp. And hope it will solve your problem.

Thứ Năm, 2 tháng 1, 2014

PATH: all you need to know

Hi all,
Previously, I write a blog about LD_LIBRARY_PATH [1]. Continuing this series, I write this blog about another important environment variable in Linux which is PATH.
PATH is the environment that contains paths to executable files. For example, /home/tranlaman/bin, /usr/local/sbin, /usr/local/bin/, /usr/sbin, or /bin.
Otherwise, LD_LIBRARY_PATH contains dynamic library for other programs.

Thứ Sáu, 20 tháng 12, 2013

HOW-TO: Making an icon licking in Ubuntu

Hi all,
After a while of using Ubuntu, I feel that everything is fine and cool. It is still something missing in Windows. They are icons. This tutorial guides you how to make an icon licking in Ubuntu. I prefer to style of learning by doing, so let start with an example.
Let save the following code in a file named matlab.desktop, and move it to /usr/share/applications. It is a system folders, and you should know that we need to use sudo.
#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Icon=/usr/share/icons/matlab_logo.gif
Name=MATLAB R2012a
Comment=Start MATLAB - The Language of Technical Computing
Exec=matlab -desktop
Categories=Development;

All you need to do is to replace a command to start your application, in this case, it is MATLAB R2012a. It should be noticed that excutable command here is that matlab. We need to create alias for matlab.
 cd /usr/local/bin/ 
 sudo ln -s /usr/local/MATLAB/R2012a/bin/matlab matlab
This trick will allow you to start Matlab from any folder, as you were trying to do. Further, you should replace icon with your logo. That's all. Then, you find an icon of Matlab in /usr/share/applications. Now you can search Matlab in Launcher Utility and send this icon to Desktop to have a licking icon such that in Windows.

I know that I need to create some icons for some applications I like since a long  time ago. But I rely on the reason that I am busy so I did not care about it. Now I change. Let work with a style, live with a style and more,  research also with a style. I am gonna figure out what style I am.
Thanks,

Thứ Năm, 11 tháng 7, 2013

LD_LIBRARY_PATH all you need to know.

Hi all,
I have spent countless hour when trying to compile the C/C++ code in Linux (Ubuntu 12.04) using GCC or G++ compiler. I met a bunch of errors and then I figured out in Ubuntu the options -I -L and LD_LIBRARY_PATH are quite important. I read README and do exactly the same but still met the errors. Consequently, it is going to save your time if you understand a little bit about -I option, -L options and LD_LIBRARY_PATH.
-I (Include) specifies the directories of included headers file needed to compile your code, for example, the #include <xxx.h>
- L (Library) specifies the directories of shared libraries or static libraries for linking. It is used with -l (not number but an alphabet) options to specify the lib name. For example, a library is libxxx.so or libxxx.a would have -l option as -lxxx.
LD_LIBRARY_PATH (LinkDynamic Library Path -- I guess :-D) specifies the directories of shared libraries for linker during the run-time [2]. Also, it is used at the link-time, when linker looks for libraries and resolve external symbols in these directories. The problems are raised because of LD_LIBRARY_PATH since the directories at the link-time and run-time are different [3]. Some issues relate to incompatible versions of required libraries.
Refer to the links bellow for hands-on errors and solutions:
* The difference between -I and -L options:
[1] http://adf.ly/Rsfwr/what-is-the-difference-between-i-and-l-in-makefile
* The difference between LD_LIBRARY_PATH and -L at the run-time:
[2] http://adf.ly/RsgVz/what-is-the-difference-between-ld-library-path-and-l-at-link-time
* Why the LD_LIBRARY_PATH is bad?
[3] http://adf.ly/RskIY/UnixResource_dir/_/ldpath.html