linux - [ linux, g++, linking] : library is in ldconf cache and Links Manually, 但不是默认

标签 linux g++ linker shared-libraries

这看起来与之前的帖子相似: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/

相关文章:

c++ - gcc 是否错过了优化 ctor 初始化列表的机会?

c++ - G++ 中的 MakeFile。可忽略的命令

ios - clang : error: linker command failed with exit code 1, 仅在设备上测试时

c - nm 命令输出中的奇怪符号名称

gcc - “–print-memory-usage” 在 GCC 中工作吗?

linux - linux启动后oracle临时ora 12505错误

c - 在 Linux 中终止后释放内存

linux - crontab -e vs/etc/crontab 中的 cronjob 条目。哪一个更好?

c - 如何从内核模块内的文件描述符获取文件名?

gcc - 在 PIC32 (MIPS32) 上运行的 C++