2017-10-13 44 views
0

我試圖編譯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抱怨什麼?我怎樣才能解決這個問題?

回答

1

您正在通過-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