而选项被传递给链接

问题描述:

我试图编译this git-repository遇到错误“与-fPIC编译”:与而选项被传递给链接

option(BUILD_PYTHON_BINDINGS "Whether or not a binary python module should be built" ON) 

This is the output of the compilation(分支功能pybind),但最有趣的部分是:

[100%] Linking CXX shared module pyVFRendering.cpython-34m.so 
/usr/bin/cmake -E cmake_link_script CMakeFiles/pyVFRendering.dir/link.txt --verbose=1 
/usr/bin/clang++ -fPIC -shared -o pyVFRendering.cpython-34m.so CMakeFiles/pyVFRendering.dir/python/vfrendering_bindings.cpp.o -flto libVFRendering.a qhull-prefix/src/qhull-build/libqhullcpp.a qhull-prefix/src/qhull-build/libqhullstatic_r.a 
/usr/bin/ld: libVFRendering.a(ArrowRenderer.cxx.o): relocation R_X86_64_32S against `glad_glGenVertexArrays' can not be used when making a shared object; recompile with -fPIC 
libVFRendering.a: error adding symbols: Bad value 
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation) 
CMakeFiles/pyVFRendering.dir/build.make:97: recipe for target 'pyVFRendering.cpython-34m.so' failed 
make[2]: *** [pyVFRendering.cpython-34m.so] Error 1 
make[2]: Leaving directory '/home/matthias/VFRendering/build' 
CMakeFiles/Makefile2:68: recipe for target 'CMakeFiles/pyVFRendering.dir/all' failed 
make[1]: *** [CMakeFiles/pyVFRendering.dir/all] Error 2 
make[1]: Leaving directory '/home/matthias/VFRendering/build' 
Makefile:127: recipe for target 'all' failed 
make: *** [all] Error 2 
CC=clang: Kommando nicht gefunden  

很明显,我通过-fPIC标志来叮当声。我不太了解错误信息。 ld抱怨什么?我怎样才能解决这个问题?

您正在通过-fPIC链接但可能不会在编译时编译时也应该传递它。

我认为这里真正的问题是,你似乎试图从几个静态库中创建一个共享库。这是不对的:你应该从目标文件创建它(当然编译时使用-fPIC)。

+0

由于某些原因,即使我使用set(CMAKE_POSITION_INDEPENDENT_CODE ON),此标志也不会用于编译ArrowRenderer.cxx.o,您是对的。我如何正确强制CMake使用这个标志? – Stein

+0

'set(CMAKE_CXX_FLAGS“-fPIC”)'可能是一种方法。否则,请查看源代码并查看它的设置。共享库通常在CMake中默认使用fPIC,所以项目中可能会出现某些问题。 –

+0

事实证明,我不得不将它传递给子项目QHULL。然后它工作。正确的标志是CMAKE_POSITION_INDEPENDENT_CODE ON – Stein