开发者

[ linux, g++, linking]: library is in ldconf cache and Links Manually, but not by default

This appears similar to 开发者_Python百科an earlier post: ld cannot find an existing library But to the best of my knowledge, it's not exactly the same situation. The following command works:

$g++  -I../../include/ -lboost_program_options-mt rips-zigzag.cpp

However this doesn't:

$ g++  -I../../include/ rips-zigzag.cpp
/tmp/ccLvW2Rq.o: In function `process_command_line_options
--snip--
undefined reference to `boost::program_options::options_description::m_default_line_length'
--snip--

The library is present in the so cache:

$ ldconfig -p | grep boost_program_options
libboost_program_options-mt.so.1.37.0 (libc6,x86-64) => /usr/lib/libboost_program_options-mt.so.1.37.0
libboost_program_options-mt.so (libc6,x86-64) => /usr/lib/libboost_program_options-mt.so

And here it is from /usr/lib:

akshan@akshan-laptop:~/work/comptop/Dionysus$ ls -l /usr/lib/*program_options*
-rw-r--r-- 1 root root 798686 2009-03-26 19:28 /usr/lib/libboost_program_options-mt.a
lrwxrwxrwx 1 root root     37 2009-10-13 21:09 /usr/lib/libboost_program_options-mt.so -> libboost_program_options-mt.so.1.37.0
-rw-r--r-- 1 root root 299224 2009-03-26 19:28 /usr/lib/libboost_program_options-mt.so.1.37.0

Any help with this is greatly appreciated. Thanks, Aravind.


ldconfig is concerned with runtime linking. you still must state the libraries during the linking stage of the build.

edit: oh and btw, the -larchive switches should come after the anything.cpp:

       The  linker will search an archive only once, at the location where  
       it is specified on the command line.  If the archive defines a sym‐  
       bol  which  was  undefined in some object which appeared before the  
       archive on the command line, the linker will include the  appropri‐  
       ate  file(s)  from the archive.  However, an undefined symbol in an  
       object appearing later on the  command  line  will  not  cause  the
       linker to search the archive again.


linking is about saying to the program in which library a symbol will be found it's necessary for static libraries but also for dynamic ones.

There may be several versions of the right library and that is what ld.so is about, not linking but loading dynamic libraries. This way a dynamically linked program won't have to open every library in the system to find it's symbols, it will only open the right one. This way the library loader merely looks for filenames to find the right library to load.

Compilers also have some default library you do not have to put in command line but not many. If you want to know these defaults just add a -v to your gcc command line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜