c++ - 创建共享对象时,不能使用针对符号 `ff_a64_muxer' 的重定位 R_X86_64_32;使用 -fPIC 重新编译

标签 c++ linux gcc openscenegraph

我正在尝试按照 github readme 构建 osg v 3.4 ,但是在 make VERBOSE=1 步骤后出现以下编译错误:

[ 94%] Linking CXX shared module ../../../lib/osgPlugins-3.4.0/osgdb_ffmpeg.so
cd /home/workdir/osg_tst/osg/build/src/osgPlugins/ffmpeg && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/osgdb_ffmpeg.dir/link.txt --verbose=1
/usr/local/bin/c++ -fPIC  -Wall -Wparentheses -Wno-long-long -Wno-import -pedantic -Wreturn-type -Wmissing-braces -Wunknown-pragmas -Wunused -Wno-deprecated-declarations -O3 -DNDEBUG -shared  -o ../../../lib/osgPlugins-3.4.0/osgdb_ffmpeg.so CMakeFiles/osgdb_ffmpeg.dir/FFmpegClocks.o CMakeFiles/osgdb_ffmpeg.dir/FFmpegDecoderAudio.o CMakeFiles/osgdb_ffmpeg.dir/FFmpegDecoder.o CMakeFiles/osgdb_ffmpeg.dir/FFmpegDecoderVideo.o CMakeFiles/osgdb_ffmpeg.dir/FFmpegImageStream.o CMakeFiles/osgdb_ffmpeg.dir/FFmpegAudioStream.o CMakeFiles/osgdb_ffmpeg.dir/FFmpegParameters.o CMakeFiles/osgdb_ffmpeg.dir/ReaderWriterFFmpeg.o  -Wl,-rpath,/home/workdir/osg_tst/osg/build/lib: ../../../lib/libosgDB.so.3.4.0 ../../../lib/libosgUtil.so.3.4.0 -Wl,-Bstatic -lavformat -lavdevice -lavcodec -lavutil -lswscale -lswresample -Wl,-Bdynamic ../../../lib/libosg.so.3.4.0 ../../../lib/libOpenThreads.so.3.3.0 -lpthread -lm -lrt -ldl -lz -lGL 
/usr/bin/ld: /usr/local/lib/gcc/x86_64-linux-gnu/12.2.0/../../../libavformat.a(allformats.o): relocation R_X86_64_32 against symbol `ff_a64_muxer' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/gcc/x86_64-linux-gnu/12.2.0/../../../libavformat.a(amr.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/gcc/x86_64-linux-gnu/12.2.0/../../../libavformat.a(anm.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/gcc/x86_64-linux-gnu/12.2.0/../../../libavformat.a(apc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
.
.
.
collect2: error: ld returned 1 exit status
make[2]: *** [src/osgPlugins/ffmpeg/CMakeFiles/osgdb_ffmpeg.dir/build.make:224: lib/osgPlugins-3.4.0/osgdb_ffmpeg.so] Error 1
make[2]: Leaving directory '/home/workdir/osg_tst/osg/build'
make[1]: *** [CMakeFiles/Makefile2:5205: src/osgPlugins/ffmpeg/CMakeFiles/osgdb_ffmpeg.dir/all] Error 2
make[1]: Leaving directory '/home/workdir/osg_tst/osg/build'
make: *** [Makefile:136: all] Error 2

错误列表还在继续,但为了清楚起见,我只显示前三个,因为它们都匹配相同的错误。

该错误建议使用 -fPIC 选项,但它显然已在显示的命令中使用。

来自gcc documentation它应该与使用的体系结构有关,但该项目也已经是 64 位的,就像我的 linux 体系结构是 x86_64 一样,那么我在这里缺少什么?

最佳答案

-fPIC 问题不在于您正在编译的项目,而在于您链接的 ffmpeg 二进制文件。注意,编译错误引用/usr/local/lib/gcc/x86_64-linux-gnu/12.2.0/../../../libavformat.a,这是你的系统安装libavformat 的一部分,ffmpeg 项目的一部分。

我建议按照说明 here 从源代码构建 ffmpeg 。如果将 --enable-pic 传递给 configure 脚本,那么它将使用 -fPIC 标志进行编译,使您能够链接到没有错误。

关于c++ - 创建共享对象时,不能使用针对符号 `ff_a64_muxer' 的重定位 R_X86_64_32;使用 -fPIC 重新编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75813648/

相关文章:

linux - 动态运行 linux shell 命令

c - 未定义功能感应

c++ - 为什么这个程序的输出在 C 和 C++ 之间不同?

我可以将数据推送/弹出到 GCC C 返回堆栈吗?

c++ - 如何在 C++ 中获得 GMT 时间和任何时区之间的差异

c++ - 通过字符串解析 double C++

C++:获取数组中char元素的索引

c++ - 最简单的二叉树插入不起作用

linux - Plone 统一安装程序缺少 Python

linux - scrot 区域不起作用的 Bash 脚本