views:

356

answers:

2

Hi all,

This appears similar to an earlier post: http://stackoverflow.com/questions/335928/linux-gcc-linking-ld-cannot-find-a-library-that-exists 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.

+4  A: 

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

edit: oh and btw, the -l*archive* 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.
just somebody
`oh and btw, the -l*archive* switches should come after the anything.cpp:` Yes, and also after *.o . I had so much hell with gcc trying to get libraries to work because of that.
Earlz
Great!! Thanks for letting me know! -A
Aravindakshan
A: 

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.

kriss
Thanks for the answer! -A
Aravindakshan