为什么会出现“ DSO丢失”的提示?即使链接器可以找到库,也会出错? [英] Why do I get "DSO missing" error even when the linker can locate the library?
问题描述
我正在针对我编写的共享库编译程序。该库又依赖于 Boost :: program_options
(在其他库中)。当我编译程序时,我当然需要提到我的库,但是会出现DSO错误:
I am compiling a program against a shared library I have written. This library in turn relies on Boost::program_options
(among other libraries). When I compile my program, I need of course to mention my library, but I get a DSO error:
g++ ism_create_conf.cc -o ism_create_conf -lglsim_ol -lglsim -lhdf5 -lgsl
/usr/bin/ld.real: /tmp/cc9mBWmM.o: undefined reference to symbol_ZN5boost15program_options8validateERNS_3anyERKSt6vectorISsSaISsEEPSsi'
//usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.55.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
我知道,如果添加 -lboost_program_options
,错误就会消失。我不明白的是
I know that the error goes away if I add -lboost_program_options
. What I don't understand is
-
即使我的程序没有直接调用Boost,为什么我必须这样做?通过我的glsim库)。
Why do I have to do this even if my program does not call Boost directly (only through my glsim library).
链接器为什么在实际找到正确的链接时想要 -lboost_program_options
库(和位置)本身(请参见错误消息的第二行)。
Why does the linker want -lboost_program_options
when it actually found the correct library (and location) by itself (see the second line of the error message).
这种情况类似于问了什么,例如在这里,但是我问的是不同的东西:我知道解决方案是在命令行中提及该库,我想知道为什么为什么即使链接器已经知道库在哪里,我也必须这样做。对于共享库的工作方式,显然我不了解,在我看来,当我使用其他共享库时,这些库可以自动调用其他需要的共享库。但是,我建立的共享库不具备此功能。
The situation is similar to what was asked e.g here, but I am asking something different: I know the solution is to mention the library in the command line, I want to know why I have to do this even if the linker already knows where the library is. There is obviously something I do not understand about how shared libraries work, it seems to me that when I use other shared libraries, these libraries can automatically call other shared libraries they need. However, the shared library I built does not have this ability.
推荐答案
现代发行版(例如 Ubuntu Natty及更高版本)启用-按需标志在其工具链中默认为。副作用之一是链接器更严格地跟踪库的顺序(不确定这样做的原因,很可能匹配静态库的情况)。
Modern distros (e.g. Ubuntu Natty and later) enable --as-needed flag by default in their toolchains. One of side-effects is that linker tracks order of libraries more strictly (not sure why this was done, probly to match static libraries case).
这篇关于为什么会出现“ DSO丢失”的提示?即使链接器可以找到库,也会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!