我使用ffmpeg安装了vcpkg install ffmpeg
当我在cmake项目中包含依赖项时,如下所示:
find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h)
find_library(AVCODEC_LIBRARY avcodec)
find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY avformat)
find_path(AVUTIL_INCLUDE_DIR libavutil/avutil.h)
find_library(AVUTIL_LIBRARY avutil)
find_path(AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h)
find_library(AVDEVICE_LIBRARY avdevice)
target_link_libraries(${TARGET_NAME} PRIVATE
${AVCODEC_LIBRARY} ${AVFORMAT_LIBRARY} ${AVUTIL_LIBRARY} ${AVDEVICE_LIBRARY}
)但是,在linux上,我得到了一个错误:
[29/29] Linking CXX shared library libjni.so
2021-11-14T12:38:02.510164800Z FAILED: libjni.so
2021-11-14T12:38:02.510171600Z : && /usr/bin/g++-11 -fPIC -O3 -DNDEBUG -shared -Wl,-soname,libjni.so -o libjni.so CMakeFiles/jni.dir/src/jni.cpp.o CMakeFiles/jni.dir/src/core/audio.cpp.o CMakeFiles/jni.dir/src/core/files.cpp.o CMakeFiles/jni.dir/src/core/fs/file_utils.cpp.o CMakeFiles/jni.dir/src/core/spectrogram.cpp.o CMakeFiles/jni.dir/src/core/utils.cpp.o -L/usr/lib/gcc/x86_64-linux-gnu/10 -Wl,-rpath,/root/build/Release/_deps/fmt-build /root/vcpkg/installed/x64-linux/lib/libfftw3f.a _deps/fmt-build/libfmt.so.8.0.1 _deps/xxhash-build/libxxhash.a /root/vcpkg/installed/x64-linux/lib/libavcodec.a /root/vcpkg/installed/x64-linux/lib/libavformat.a /root/vcpkg/installed/x64-linux/lib/libavutil.a /root/vcpkg/installed/x64-linux/lib/libavdevice.a _deps/kistream_proto_cpp-build/libgenerated_srcs.a -lm -Wl,--as-needed /root/vcpkg/installed/x64-linux/lib/libprotobuf.a -lpthread && :
2021-11-14T12:38:02.510185200Z /usr/bin/ld: /root/vcpkg/installed/x64-linux/lib/libavcodec.a(h264_intrapred_10bit.o): warning: relocation against `ff_pw_512' in read-only section `.text'
2021-11-14T12:38:02.510187600Z /usr/bin/ld: /root/vcpkg/installed/x64-linux/lib/libavcodec.a(vc1dsp_mmx.o): relocation R_X86_64_PC32 against symbol `ff_pw_9' can not be used when making a shared object; recompile with -fPIC发布于 2022-01-04 06:59:30
我想,你的问题与“独立立场守则”有关。如果通过在vcpkg中提供-fPIC选项进行编译,则可以解决此问题。
您可以查看这 github发行的vcpkg回购。给出了一个如何将编译器选项添加到vcpkg`s的端口CMake文件的例子。
https://stackoverflow.com/questions/69964899
复制相似问题