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


This appears similar to 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
undefined reference to `boost::program_options::options_description::m_default_line_length'

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.

Best Solution

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.
Related Question