我正在尝试按照 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/