如何在cmake中设置rpath origin?

8

我发现了Cmake: How to set rpath to ${ORIGIN} with cmake,但我的cmake没有target_link_options。

我不是在安装二进制文件,而是只用RUNTIME_OUTPUT_DIRECTORY“安装”它,因此我认为CMAKE_INSTALL_RPATH不起作用。即使如此,我还是尝试了建议中的SET(CMAKE_INSTALL_RPATH "$\{ORIGIN\}"),但是我得到了以下结果:

  Syntax error in cmake code at

  .../CMakeLists.txt:25

  when parsing string

    $\{ORIGIN\}

  Invalid escape sequence \{

我需要设置这个rpath,它是我在Makefile中使用的:

-rpath=\$$ORIGIN/lib

如何在cmake中实现?


你正在使用哪个版本的CMake? - Kevin
3个回答

10

以下对我在3.14上有效

  set(CMAKE_INSTALL_RPATH $ORIGIN)

这是Craig Scott在他的CppCon 2019演讲《面向库作者的深入CMake》中推荐的内容(第100/110页)。

3
根据幻灯片,重要的是在add_executable之前加入那一行。 - thejinx0r
请注意,这适用于make install,而不是make - undefined

3

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接