为外部项目设置RPATH?

时间:2015-09-25 16:14:47

标签: c++ macos cmake dyld rpath

我正在尝试设置一个项目,我的存储库将所有依赖项作为git子模块导入,以便于开发。我的同事可以简单地克隆回购,git submodule update --init --recursivecmake .make,并拥有一个完全正常工作的开发环境。目录结构设置为顶级CMakeLists.txt的超级构建,使用ExternalProject_Add构建所有子模块,从而产生以下结构:

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

CMakeLists.txt看起来像这样:

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
)

构建过程非常有效。在顶级我make,依赖项已安装到usr,我cd已安装到my_project,我的工作,所有已构建的共享库都已找到并链接,I& #39;快乐。

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

有没有什么方法可以将自定义安装位置添加到RPATH的构建时库和可执行文件?

一些注意事项:

  • 这个问题似乎只影响OS X.Linux根本没有表现出这些问题。
  • 设置DYLD_LIBRARY_PATH以包含自定义安装位置。但是,这会给设置增加一个额外的步骤,当我尝试调试安装问题时会很烦人。
  • 设置DYLD_FALLBACK_LIBRARY_PATH也有效,虽然这也不是一个好选项,因为它还添加了一个额外的设置,而自制软件用户不喜欢这个选项。

1 个答案:

答案 0 :(得分:1)

对于使用public class JavaAgent extends AgentBase{ private static int erros=0; private static int count=0; public int getErros(){return erros;} public int getCount(){return count;} public void NotesMain() { System.out.println("\n\nStart of Agente!"); try { Session session = getSession(); Database db = session.getCurrentDatabase(); View vw = db.getView("vwTodas"); JFileChooser fc = new JFileChooser(); //Get the file by file chooser /* Filter FileReader through a Buffered read to read a line at a time */ BufferedReader bufRead = null; try{ //read the file //work in the file } }catch(IOException a){ JOptionPane.showMessageDialog(null,"Problems reading the file!","Problems!",JOptionPane.INFORMATION_MESSAGE); }finally{ try{ bufRead.close(); }catch(IOException b){ JOptionPane.showMessageDialog(null, "Problems closing the file!", "Problems!", JOptionPane.INFORMATION_MESSAGE); } } System.out.println("\n\nEnd of Agente!"); JOptionPane.showMessageDialog(frame,"Documents sent: " + count + "\nErrors during the import: " + erros + "\nTotal: " + (count+erros),"Erro",JOptionPane.ERROR_MESSAGE); } } catch(NotesException e) { e.printStackTrace(); } } 构建的可执行文件和共享库,将my_project/CMakeLists.txt添加到安装路径,并使CMake以下列方式使用该安装路径链接构建树中的目标:

${INSTALL_PREFIX}/lib

这样,在从构建树运行可执行文件时,加载程序应该找到安装到set_target_properties(my_exe PROPERTIES INSTALL_RPATH "${INSTALL_PREFIX}/lib") set_target_properties(my_exe PROPERTIES BUILD_WITH_INSTALL_RPATH ON) 目录的外部库。