compile opencv 3 on ubuntu 16.04 linking error: /usr/lib/x86_64-linux-gnu/libsoxr.so.0: undefined reference to `GOMP_parallel@GOMP_4.0'

compile opencv 3 on ubuntu 16.04 linking error: /usr/lib/x86_64-linux-gnu/libsoxr.so.0: undefined reference to `GOMP_parallel@GOMP_4.0'

尝试通过从源代码构建在 Ubuntu 16.04 上安装 openCV 3.1、CUDA 8.0.44。

以下是我在编译过程中遇到的错误。

Scanning dependencies of target opencv_test_video
[ 37%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/test_optflowpyrlk.cpp.o
[ 37%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/test_accum.cpp.o
[ 37%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/test_kalman.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/test_ecc.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/test_tvl1optflow.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/test_main.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/test_camshift.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/ocl/test_optflowpyrlk.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/ocl/test_optflow_farneback.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/ocl/test_bgfg_mog2.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/ocl/test_optflow_tvl1flow.cpp.o
[ 38%] Building CXX object modules/video/CMakeFiles/opencv_test_video.dir/test/test_estimaterigid.cpp.o
[ 38%] Linking CXX executable ../../bin/opencv_test_video
//usr/lib/x86_64-linux-gnu/libsoxr.so.0: undefined reference to `GOMP_parallel@GOMP_4.0'
collect2: error: ld returned 1 exit status
modules/video/CMakeFiles/opencv_test_video.dir/build.make:391: recipe for target 'bin/opencv_test_video' failed
make[2]: *** [bin/opencv_test_video] Error 1
CMakeFiles/Makefile2:3336: recipe for target 'modules/video/CMakeFiles/opencv_test_video.dir/all' failed
make[1]: *** [modules/video/CMakeFiles/opencv_test_video.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

我认为问题与 openMP 或 ld 配置有关。

详细配置如下:

  1. LD_LIBRARY_PATH:

/usr/lib/nvidia-current:/usr/local/cuda/lib64:/usr/local/cuda/lib

  1. GCC 版本:5.4.0

  2. CMake配置命令:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=ON -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" ..

首先,我认为这个问题是因为我安装了 Anaconda 并将其放入我的 PATH

Anaconda 和系统默认使用不同的 GCC 版本。对于 Ubuntu 16.04,GCC 版本是 5.4.0 但是 Anaconda 只提供 GCC 4(我不记得是 4.4 还是 4.8)。虽然我用的是系统默认的gcc编译opencv,但是莫名其妙的会找到Anaconda里面的lib,导致了这个问题。

我认为有两种方法可以解决这个问题。

  1. 方法一:通过选项-D WITH_OPENMP=ON,或者使用cmake-gui时勾选WITH-OPENMP.
  2. 方法 2:从 $PATHLD_LIBRARY_PATH 中删除 Anaconda。

我有一个类似的问题,但另一个库文件 usr/lib/x86_64-linux-gnu/libgdcmMSFF.so.2.8: undefined reference to `uuid_generate@UUID_1.0' 在这里寻找我的 issue。 我认为您可能还会收到警告,某些目录中的文件可能与隐式目录中的库冲突:

解决方案 在我的例子中:我在 bashrc 文件中将 /usr/lib/x86_64-linux-gnu 添加到 LD_LIBRARY_PATH 并获取了它。然后,我把anaconda3/lib下的libuuid库文件移到了anaconda3/libuuid下。我没有更多的错误,我希望这也能奏效。