为什么 cmake 无法定位 C++/C++ABI 运行时依赖项?

发布于 2025-01-09 10:29:51 字数 1439 浏览 0 评论 0原文

我试图编写一个 cmake 脚本来自动安装我的目标:

set_target_properties(tiflash PROPERTIES INSTALL_RPATH "$ORIGIN/")
install (TARGETS A
         COMPONENT A-release
         DESTINATION "."
         RUNTIME_DEPENDENCY_SETA-dependency)
install (RUNTIME_DEPENDENCY_SET A-dependency
         COMPONENT A-release
         DESTINATION "."
         POST_EXCLUDE_REGEXES "libdl.*" "libc-.*" "libc\\..*" "libgcc_s.*" "librt.*" "libm.*" "ld-.*" "libpthread.*")

在这种情况下,RUNTIME_DEPENDENCY_SET 应该包括 libc++.so.1libc++abi .so.1 因为我正在使用 LLVM 工具链,并且我想将运行时库与我的可执行文件打包在一起。

CMake 确实包含了预期的库;但它抱怨 cmake 无法找到 libc++.so.1libc++abi.so.1。 (我想这是因为 libc++.so.1libc++abi.so.1 安装在未注册的位置 /usr/local/lib/ x86_64-unknown-linux-gnu)。

我可以通过在安装函数中添加诸如 DIRECTORIES /usr/local/lib/x86_64-unknown-linux-gnu 之类的东西来解决这个问题。但是,将会发出警告。该文件说:

如果在这样的目录中找到它,则会发出警告,因为这意味着该文件不完整(它没有列出包含其依赖项的所有目录)

我很好奇它没有列出所有包含其依赖项的目录在这里意味着什么?在什么名单里? Rpaths 还是其他什么?

我尝试将 /usr/local/lib/x86_64-unknown-linux-gnu 放入目标的 BUILD_RPATH 中。它不起作用。 (我已经检查了生成的安装脚本,它在构建目标上调用 file(GET_RUNTIME_DEPENDENCIES) ;所以我认为安装 rpath 不会影响结果。)

我还有 LD_LIBRARY_PATHLIBRARY_PATH< /code> 在我的环境中设置(包含 /usr/local/lib/x86_64-unknown-linux-gnu)。并且CMAKE_PREFIX_PATH指向/usr/local/

I was trying to write a cmake script to auto install my targets:

set_target_properties(tiflash PROPERTIES INSTALL_RPATH "$ORIGIN/")
install (TARGETS A
         COMPONENT A-release
         DESTINATION "."
         RUNTIME_DEPENDENCY_SETA-dependency)
install (RUNTIME_DEPENDENCY_SET A-dependency
         COMPONENT A-release
         DESTINATION "."
         POST_EXCLUDE_REGEXES "libdl.*" "libc-.*" "libc\\..*" "libgcc_s.*" "librt.*" "libm.*" "ld-.*" "libpthread.*")

In this case, RUNTIME_DEPENDENCY_SET is supposed to include libc++.so.1 and libc++abi.so.1 as I was using LLVM toolchain and I wanted to package the runtime libs with my executables.

CMake did include the expected libs; but it complained that cmake cannot locate libc++.so.1 and libc++abi.so.1. (I suppose this was because libc++.so.1 and libc++abi.so.1 were installed in an unregistered location /usr/local/lib/x86_64-unknown-linux-gnu).

I can walk around this problem by adding sth like DIRECTORIES /usr/local/lib/x86_64-unknown-linux-gnu to the install function. However, warnings will be issued. The document says:

If it is found in such a directory, a warning is issued, because it means that the file is incomplete (it does not list all of the directories that contain its dependencies)

I am curious what does it does not list all of the directories that contain its dependencies mean here? In what list? Rpaths or something else?

I tried to put /usr/local/lib/x86_64-unknown-linux-gnu to BUILD_RPATH of my target. It did not work. (I have checked the generated install script, it calls file(GET_RUNTIME_DEPENDENCIES) on the building target; so I suppose install rpath won't affect the results.)

I also have LD_LIBRARY_PATH and LIBRARY_PATH set in my environment (which contains /usr/local/lib/x86_64-unknown-linux-gnu). And CMAKE_PREFIX_PATH is pointing to /usr/local/.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

じ违心 2025-01-16 10:29:51

我刚刚注意到 cmake 解释了解析过程:

  1. 如果依赖文件没有任何 RUNPATH 条目,并且该库存在于依赖文件的 RPATH 条目之一或其父条目中(按此顺序),则依赖关系将得到解决到该文件。

  2. 否则,如果依赖文件具有任何 RUNPATH 条目,并且该库存在于这些条目之一中,则依赖关系将解析为该文件。

  3. 否则,如果该库存在于 ldconfig 列出的目录之一中,则依赖关系将解析为该文件。

  4. 否则,如果该库存在于 DIRECTORIES 条目之一中,则依赖关系将解析为该文件。在这种情况下,会发出警告,因为在其中一个目录中找到文件意味着依赖文件不完整(它不会列出从中提取依赖项的所有目录)。

  5. 否则,依赖关系无法解决。

那么,我设置了运行时路径,那么问题出在哪里呢?

事实证明,A 依赖于导入的库,比方说,B

但是,B 还依赖于 libc++.so.1 并且它不设置运行时路径。我猜想 cmake 以 DFS 方式进行解析,并在根之前完成所有叶子。因此,错误实际上是针对 B 生成的。


作为解决方案,我认为如果我正确执行 ldconfig 会更好。

I just noticed that cmake explained the resolution procedure:

  1. If the depending file does not have any RUNPATH entries, and the library exists in one of the depending file's RPATH entries, or its parents', in that order, the dependency is resolved to that file.

  2. Otherwise, if the depending file has any RUNPATH entries, and the library exists in one of those entries, the dependency is resolved to that file.

  3. Otherwise, if the library exists in one of the directories listed by ldconfig, the dependency is resolved to that file.

  4. Otherwise, if the library exists in one of the DIRECTORIES entries, the dependency is resolved to that file. In this case, a warning is issued, because finding a file in one of the DIRECTORIES means that the depending file is not complete (it does not list all the directories from which it pulls dependencies).

  5. Otherwise, the dependency is unresolved.

So, I set the runtime path, what is the problem then?

It turns out that A depends on an imported lib, let us say, B.

However, B also depends on libc++.so.1 and it does not set the runtime path. I guess cmake do the resolution in a DFS manner and finalize all leaves before roots. So, the error is actually generated for B.


As a solution, I think it would be better if I do ldconfig properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文