cmake 3.9 target_link_libraries到静态导入库失败。相同的CMakefile适用于CMake 2.8.12

时间:2017-11-15 03:48:37

标签: static cmake linker shared

我有以下CMakefile适用于CMake 2.8.12但升级到3.9后失败:

add_library(extlib STATIC IMPORTED GLOBAL)
set_property( TARGET extlib PROPERTY IMPORTED_LOCATION ${EXTERNAL_LIB_DIR}/extlib.a )
add_executable( myApp myApp.cpp )
target_link_libraries( myApp extlib)

cmake生成Makefile。但是失败了:

/usr/bin/ld: ../../ext/lib/extlib.a(extlib.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC

我运行make VERBOSE = 1显示以下内容:

/usr/bin/c++    -rdynamic CMakeFiles/myApp.dir/myApp.cpp.o  -o myApp -Wl,-rpath,/root/myApp/ext/lib ../../ext/lib/extlib.a

extlib.a作为共享库链接。

CMakefile对2.8.12没有问题。

我需要修改什么才能使其在3.9中运行?

谢谢!

0 个答案:

没有答案