代码之家  ›  专栏  ›  技术社区  ›  divflex

CMake找不到.so哪个是符号链接文件

  •  0
  • divflex  · 技术社区  · 3 年前

    平台:ubuntu22.04 我正在使用cmake链接到第三方库。它看起来像:

    // Those two files are identical. 
    // abc.so is the original file and libabc.so is a copy
    
    // ${shared} is an absolute path
    ${shared}/libabc.so
    ${shared}/abc.so
    

    我的CMakeLists.txt:

    LINK_DIRECTORIES(${shared})
    
    ADD_EXECUTABLE(main ...)
    
    TARGET_LINK_LIBRARIES(main libabc.so)
    

    到目前为止,它运行良好。你可能已经注意到我 ${shared}/libabc.so 和 ${shared}/abc.so 同时它们完全相同。所以我删除了libabc.So(abc.So是原始文件),并创建了一个链接文件 ln -s relative_path/shared/abc.so relative_path/shared/libabc.so . 但我得到了:

    /usr/bin/ld: cannot find -labc: No such file or directory
    collect2: error: ld returned 1 exit status
    

    当libabc.so确实存在时,为什么我会得到这个错误?

    1 回复  |  直到 3 年前
        1
  •  0
  •   starball Martin Jorgensen    3 年前

    除非你跑了 ln -s shared/abc.so shared/libabc.so 从根目录(shell的当前工作目录在根目录中),它应该是 ln -s /shared/abc.so /shared/libabc.so 。您想要的是绝对路径,而不是相对路径。

    不确定根据您的 ${shared} 变量,注释来自 the docs for link_directories :

    添加链接器应在其中搜索库的路径。提供给此命令的相对路径被解释为相对于当前源目录

    此外,我相信你 target_link_libraries(main libabc.so) 可以是 target_link_libraries(main abc) , as documented in the target_link_library docs 的“普通库名称”形式 <item> 参数。

    推荐文章