compiler-errors - 将选项传递给链接器时出现 "recompile with -fPIC"错误

标签 compiler-errors cmake linker

我正在尝试编译 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在提示什么?我怎样才能解决这个问题?

最佳答案

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

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

关于compiler-errors - 将选项传递给链接器时出现 "recompile with -fPIC"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46731707/

相关文章:

java - 我的代码编译时出现错误,但在运行时执行良好

c++ - 我想用 CMake 生成和编译 Visual Studio 项目我需要从构建中排除单元测试文件。有没有办法做到这一点?

c++ - Qt Creator 无法识别在 Qt : location ui_*. h 中使用 CMake

linux - 强制 GCC 静态链接,例如pthreads(而不是动态链接)

c++ - 静态 libstdc++.a 中的全局符号在共享 libstdc++.so 中是局部的

java - 尝试从列表构造 HashSet<Integer> 时参数不匹配 - 为什么?

compilation - 使用 grunt-contrib-stylus 进行编译时,手写笔出现 "EOS"错误

dictionary - 了解链接器映射文件 (MS Visual Studio 2005)

c# - 不可发音成员 ''不能像方法一样使用

c++ - CMake Qt 项目中的链接和 UIC 顺序