构建涉及cmake的项目,如何让它了解库

dal*_*ala 10 linker cross-platform cmake

当我尝试在64位linux(debian)机器上使用cmake和gcc构建这个项目时,我从链接器收到错误:

Linking C executable ../../../../cpsadamsx
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlopen'
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlclose'
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlerror'
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlsym'
collect2: ld returned 1 exit status
make[2]: *** [cpsadamsx] Error 1
make[1]: *** [sundials/examples/cpodes/serial/CMakeFiles/cpsadamsx.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Run Code Online (Sandbox Code Playgroud)

显然dlopen,dlclose,dlerror和dlsym是对libdl.so的引用.我在/lib64/libdl.so.2中有该库,但为什么找不到它?

它会是一个正常的'./configure; 使; make install'-path我可以设置LIBS变量并发出这样的configure命令(我认为):

export LIBS=-ldl && ./configure
Run Code Online (Sandbox Code Playgroud)

但是我现在该怎么做?

更新:

所以似乎找到了(或至少一个)库,但不包含有问题的符号.也许它尝试使用/ lib中的32位库?

有没有办法反汇编/lib64/libdl.so.2以确保它有引用dlopen等?

现在问题似乎是将构建工具引导到库的正确版本.

Myt*_*hli 35

由于这个问题出现在谷歌上,这两个答案都没有指向正确的解决方案,它是:

在您的CMakeLists.txt中添加${CMAKE_DL_LIBS}针对idl的链接.它看起来应该类似于:

target_link_libraries(ExpandableTest
    ${CMAKE_DL_LIBS}
    Expandable
    ExpandableTestLibrary
)
Run Code Online (Sandbox Code Playgroud)

  • 我想补充一点,我必须将$ {CMAKE_DL_LIBS}移动到列表中的最后一个位置.否则它对我不起作用 (3认同)

dim*_*mba 1

可能您需要添加 target_link_libraries() - 请参阅链接文本