这看起来与之前的帖子相似:ld cannot find an existing library但据我所知,情况并不完全相同。以下命令有效:
$g++ -I../../include/ -lboost_program_options-mt rips-zigzag.cpp
但是这不是:
$ 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--
库存在于so缓存中:
$ 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
这是来自/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
非常感谢您对此提供的任何帮助。 谢谢, 亚拉汶。
最佳答案
ldconfig 与运行时链接有关。您仍然必须在构建的链接阶段声明库。
编辑:哦,顺便说一句,-larchive 开关应该在 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.
关于linux - [ linux, g++, linking] : library is in ldconf cache and Links Manually, 但不是默认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1745880/