使用CMake链接导入的共享库时,请避免使用完整路径

时间:2018-06-27 21:53:47

标签: cmake shared-libraries

我有一个CMake(版本3.12)项目,用于链接外部构建的共享库(通过Autotool)。这是我的方法。

add_library(open_tix SHARED IMPORTED GLOBAL)
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-L$ENV{OPENROAD}/tools/lib/$ENV{OPENROADOS}")
set_property(TARGET open_tix PROPERTY IMPORTED_LOCATION $ENV{OPENROAD}/tools/lib/$ENV{OPENROADOS}/libopen_tix${CMAKE_SHARED_LIBRARY_SUFFIX})

但是,当我ldd程序(flow)时,总是看到此导入库(libopen_tix.so)的完整路径,该路径不可重定位:

ldd flow
  linux-vdso.so.1 =>  (0x00007ffd4798e000)
  ../../../tools/lib/Linux-x86_64/libopen_tix.so (0x00007fe9a3a16000)
  libXft.so.2 => /usr/lib64/libXft.so.2 (0x00000036ae800000)
  libfontconfig.so.1 => /usr/lib64/libfontconfig.so.1 (0x00000036a4c00000)
  libSM.so.6 => /usr/lib64/libSM.so.6 (0x000000328ba00000)
  libICE.so.6 => /usr/lib64/libICE.so.6 (0x00000036a8400000)

但是,我希望它是

linux-vdso.so.1 =>  (0x00007ffd4798e000)
libopen_tix.so => (0x00007fe9a3a16000)
libXft.so.2 => /usr/lib64/libXft.so.2 (0x00000036ae800000)
libfontconfig.so.1 => /usr/lib64/libfontconfig.so.1 (0x00000036a4c00000)
libSM.so.6 => /usr/lib64/libSM.so.6 (0x000000328ba00000)
libICE.so.6 => /usr/lib64/libICE.so.6 (0x00000036a8400000)

我应该为我的CMake做些什么?

0 个答案:

没有答案