如何在try_run命令中传递-fPIC

时间:2016-11-23 10:25:52

标签: compiler-errors cmake

我正在使用cmake命令try_run来检查库。这在自制的公式(在Mac上)上运行良好,但是当在linux机器上执行相同的脚本时,我收到警告,我必须“用-fPIC编译代码(-fPIE是不够的)。”

In file included from /usr/include/qt5/QtCore/qchar.h:43:0,
                 from /usr/include/qt5/QtCore/qstring.h:48,
                 from /usr/include/qt5/QtCore/QString:1,
                 from /usr/include/qt5/QtCrypto/qca_core.h:36,
                 from /usr/include/qt5/QtCrypto/qca.h:36,
                 from /usr/include/qt5/QtCrypto/QtCrypto:1,
                 from qcaossl.cpp:2:
/usr/include/qt5/QtCore/qglobal.h:1113:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
 #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\

这是try_run命令:

try_run(RUN_RESULT COMPILE_RESULT
  ${CMAKE_BINARY_DIR} ${TESTCPP}
  CMAKE_FLAGS "-DCMAKE_CXX_STANDARD=11"
              "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
              "${QCA_INCLUDE_DIRECTORIES}"
              "${QCA_LINK_LIBRARIES}"
  COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
)

当我查看用于编译测试代码的生成代码时,-fPIE将传递给编译器。如果删除了指令-DCMAKE_POSITION_INDEPENDENT_CODE=ON-fPIE就会消失。

我尝试设置"-DCMAKE_CXX_FLAGS=-fPIC",但这也无济于事。

这里可能出现什么问题?

0 个答案:

没有答案