【问题标题】:Building project involving cmake, how do I make it aware of libraries构建涉及 cmake 的项目,我如何让它知道库
【发布时间】:2009-08-13 20:57:24
【问题描述】:

当我尝试在 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....

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

会不会是一个普通的 './configure;制作; make install'-path 我可以设置 LIBS 变量并发出这样的配置命令(我认为):

export LIBS=-ldl && ./configure

但是我现在该怎么做呢?

更新:

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

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

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

【问题讨论】:

    标签: cross-platform linker cmake


    【解决方案1】:

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

    在您的 CMakeLists.txt 中添加 ${CMAKE_DL_LIBS} 以链接到 idl。 它应该看起来像这样:

    target_link_libraries(ExpandableTest
        ${CMAKE_DL_LIBS}
        Expandable
        ExpandableTestLibrary
    )
    

    【讨论】:

    • 这是更兼容的anwser,应该是公认的。
    • 我想补充一点,我必须将 ${CMAKE_DL_LIBS} 移动到列表中的最后一个位置。否则它对我不起作用
    【解决方案2】:

    您可能需要添加 target_link_libraries() - 请参阅 link text

    【讨论】:

    • 这可能行得通,但它不是“我的”项目,所以最好我不想编辑 CMakeLists.txt 文件。
    【解决方案3】:

    在 CMakeLists.txt 中添加它,它应该可以工作:

    SET (CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -ldl")
    

    【讨论】:

    • 这是 linux 特定的,并不是最好的解决方案,请参阅上面的 CMAKE_DL_LIBS 参考。
    猜你喜欢
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 2018-02-19
    相关资源
    最近更新 更多