【问题标题】:Got "recompile with -fPIC" error while the option is passed to the linker将选项传递给链接器时出现“使用 -fPIC 重新编译”错误
【发布时间】:2017-10-13 14:02:09
【问题描述】:

我正在尝试用

编译this git-repository(分支:feature-pybind)
option(BUILD_PYTHON_BINDINGS "Whether or not a binary python module should be built" ON)

This is the output of the compilation,但有趣的是:

[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 标志传递给 clang。我真的不明白错误信息。 ld在抱怨什么?我该如何解决这个问题?

【问题讨论】:

    标签: compiler-errors cmake linker


    【解决方案1】:

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

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

    【讨论】:

    • 您是对的,出于某种原因,即使我使用 set(CMAKE_POSITION_INDEPENDENT_CODE ON),此标志也不用于编译 ArrowRenderer.cxx.o。如何正确强制 CMake 使用此标志?
    • set(CMAKE_CXX_FLAGS "-fPIC") 可能是一种方式。否则,请查看源代码并查看它是如何设置的。共享库通常在 CMake 中默认使用 fPIC,因此项目中可能会出现问题。
    • 原来我还得把它传递给子项目QHull。然后它起作用了。正确的标志是 CMAKE_POSITION_INDEPENDENT_CODE ON
    猜你喜欢
    • 2013-09-20
    • 1970-01-01
    • 2023-04-08
    • 2015-01-18
    • 1970-01-01
    • 2018-05-14
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    相关资源
    最近更新 更多