设置外部项目的RPATH? [英] Setting the RPATH for external projects?

查看:314
本文介绍了设置外部项目的RPATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置一个项目,我的仓库导入所有依赖项作为git子模块,以方便开发。我的同事可以简单克隆repo, git submodule update --init --recursive cmake。 make ,并拥有一个完全可用的开发环境。目录结构设置为具有superbuild一个的CMakeLists.txt 在那建立使用所有子模块的顶级 ExternalProject_Add ,产生以下结构:

  root 
- CMakeLists.txt(superbuild)
- git_submodule_1
- git_submodule_2
- USR
- LIB
- 包括
- MY_PROJECT
- 的CMakeLists.txt(项目)

CMakeLists.txt 看起来像这样:

  SET(INSTALL_PREFIX $ {CMAKE_SOURCE_DIR} / USR)

#安装使用$ {INSTALL_PREFIX} git_submodule_1作为前缀
ExternalProject_Add( ...)

#使用$ {} INSTALL_PREFIX安装git_submodule_2作为前缀
ExternalProject_Add(...)

ExternalProject_Add(
MyProject的
$ PREFIX {} CMAKE_SOURCE_DIR / MY_PROJECT
依赖ExternalProject_git_submodule_1 ExternalProject_git_submodule_2

$ SOURCE_DIR {} CMAKE_SOURCE_DIR / MY_PROJECT
CMAKE_ARGS
-DCMAKE_LIBRARY_PATH:字符串= $ {} INSTALL_PREFIX / LIB
-DCMAKE_PROGRAM_PATH:字符串= $ {} INSTALL_PREFIX / bin中
-DCMAKE_INCLUDE_PATH:字符串= $ {} INSTALL_PREFIX /包括

#等,没有什么非标准这里

构建过程非常棒。 I make 在顶层,依赖项安装到 usr ,I cd into my_project ,我做我的工作,所有建立的共享库被发现和链接,我很高兴。



但是,当我在OS X上运行一个可执行文件时,内置 my_project ,我发现动态库放置到 usr / lib 目录中找不到。看起来CMake只设置了在项目目录中构建的库的 RPATH ,在这种情况下它只是 my_project



有任何方法我可以添加自定义安装位置到 RPATH 构建时库和可执行文件?



几个备注:




  • 此问题只会影响OS X. Linux根本不会出现这些问题。

  • 设置 DYLD_LIBRARY_PATH 以包括自定义安装位置工程。然而,这增加了一个额外的步骤,安装,当我尝试调试安装问题时,它很烦人。

  • 设置 DYLD_FALLBACK_LIBRARY_PATH 也能工作,虽然这也不是一个很好的选择,因为它也增加了一个额外的设置,以及自制赢得用户 t喜欢这个选项。


解决方案

对于使用 my_project / CMakeLists .txt 添加 $ {INSTALL_PREFIX} / lib 到安装rpath,并使CMake链接在构建树中的目标与安装rpath在下列方式:

  set_target_properties(my_exe性能INSTALL_RPATH$ {INSTALL_PREFIX} / lib目录)
set_target_properties(my_exe性能BUILD_WITH_INSTALL_RPATH ON)

这样,加载器应该找到安装到 $从构建树运行可执行文件时的{CMAKE_SOURCE_DIR} / usr / lib 目录。


I'm trying to setup a project where my repository imports all dependencies as git submodules for easy development. My colleagues can simply clone the repo, git submodule update --init --recursive, cmake . and make and have a fully working dev environment in place. The directory structure is setup as a superbuild with a CMakeLists.txt at the top level that builds all the submodules using ExternalProject_Add, resulting in the following structure:

root
 - CMakeLists.txt (superbuild)
 - git_submodule_1
 - git_submodule_2
 - usr
    - lib
    - include
 - my_project
    - CMakeLists.txt (project)

The CMakeLists.txt looks something like this:

SET (INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/usr)

# Install git_submodule_1 with ${INSTALL_PREFIX} as a prefix
ExternalProject_Add( ... )

# Install git_submodule_2 with ${INSTALL_PREFIX} as a prefix
ExternalProject_Add( ... )

ExternalProject_Add(
    MyProject
    PREFIX ${CMAKE_SOURCE_DIR}/my_project
    DEPENDS ExternalProject_git_submodule_1 ExternalProject_git_submodule_2

    SOURCE_DIR ${CMAKE_SOURCE_DIR}/my_project
    CMAKE_ARGS
      -DCMAKE_LIBRARY_PATH:string=${INSTALL_PREFIX}/lib
      -DCMAKE_PROGRAM_PATH:string=${INSTALL_PREFIX}/bin
      -DCMAKE_INCLUDE_PATH:string=${INSTALL_PREFIX}/include

    # etc, nothing nonstandard here
)

The build process works great. I make at the top level, dependencies are installed into usr, I cd into my_project, I do my work, all the built shared libraries are found and linked, I'm happy.

However, when I go to run an executable on OS X built inside my_project, I find that the dynamic libs placed into the usr/lib directory cannot be found. It appears that CMake only sets the RPATH for libraries built within the project directory, which in this case is just my_project.

Is there any way I can add the custom install location to the the RPATH for build-time libraries and executables?

A few notes:

  • This issue only appears to affect OS X. Linux doesn't exhibit these problems at all.
  • Setting the DYLD_LIBRARY_PATH to include the custom install location works. However, this adds an additional step to the setup, and it gets annoying when I try to debug installation issues.
  • Setting the DYLD_FALLBACK_LIBRARY_PATH also works, although that's also not a good option because it also adds an additional set, and homebrew users won't like this option.

解决方案

For the executables and shared libraries built with my_project/CMakeLists.txt add ${INSTALL_PREFIX}/lib to the install rpath and also make CMake link the targets in the build tree with that install rpath in the following way:

set_target_properties(my_exe PROPERTIES INSTALL_RPATH "${INSTALL_PREFIX}/lib")
set_target_properties(my_exe PROPERTIES BUILD_WITH_INSTALL_RPATH ON)

That way the loader should find the external libraries installed to the ${CMAKE_SOURCE_DIR}/usr/lib directory upon running an executable from the build tree.

这篇关于设置外部项目的RPATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆