English 中文(简体)
[ 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
--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.





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签