OpenCV链接错误

时间:2017-06-16 14:12:42

标签: c++ opencv linker

链接另一个共享库时,在构建过程中首次出现相同的错误。然后我添加了BUILD_SHARED_LIBS = OFF,所以现在它只出现在最后。最后两个选项也被添加,希望修复它。使用LinuxMint 17。

[ 99%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/deblurring.cpp.o
[ 99%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/motion_stabilizing.cpp.o
Linking CXX static library ../../lib/libopencv_videostab.a
[ 99%] Built target opencv_videostab
[ 99%] Generating pyopencv_generated_include.h, pyopencv_generated_funcs.h, pyopencv_generated_types.h, pyopencv_generated_type_reg.h, pyopencv_generated_ns_reg.h
Scanning dependencies of target opencv_python2
[ 99%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o
Linking CXX shared module ../../lib/cv2.so
/usr/bin/ld: //usr/local/lib/libavformat.a(allformats.o): relocation R_X86_64_32 against `ff_a64_muxer' can not be used when making a shared object; recompile with -fPIC
//usr/local/lib/libavformat.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/cv2.so] Error 1
make[1]: *** [modules/python2/CMakeFiles/opencv_python2.dir/all] Error 2
make: *** [all] Error 2

命令:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=/home/serj/work/beautytorch/venv/bin/python \
-D BUILD_EXAMPLES=OFF \
-D BUILD_SHARED_LIBS=OFF  \
-D CMAKE_CXX_FLAGS=-fPIC \
-D WITH_IPP=OFF \
..

1 个答案:

答案 0 :(得分:0)

ffmpeg应该使用-fPIC进行编译。 enter link description here我从源代码编译ffmpeg。卸载后,opencv链接正常。