2

I am currently trying to build a version of opencv, featuring cuda, on my arch linux computer. For that, I use opencv-cuda-git as base version. Additionally, I modified the PKGBUILD and added additional flags to further adapt opencv to my system.

However, everytime I run the buildprocess (makepkg csri), it fails with following error message:

[ 16%] Building CXX object modules/hdf/CMakeFiles/example_hdf_create_groups.dir/samples/create_groups.cpp.o
cd /home/tobias/builds/opencv-cuda-git/src/opencv/build/modules/hdf && /usr/bin/cmake -E cmake_link_script CMakeFiles/example_hdf_create_groups.dir/link.txt --verbose=1
/bin/g++-6  -std=c++11   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -fvisibility=hidden -fvisibility-inlines-hidden -Wno-invalid-offsetof -O3 -DNDEBUG  -DNDEBUG  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now  -Wl,--gc-sections   -rdynamic CMakeFiles/example_hdf_create_groups.dir/samples/create_groups.cpp.o  -o ../../bin/example_hdf_create_groups  -L/opt/cuda/lib64 ../../lib/libopencv_hdf.so.3.4.0 ../../lib/libopencv_highgui.so.3.4.0 ../../lib/libopencv_videoio.so.3.4.0 ../../lib/libopencv_imgcodecs.so.3.4.0 ../../lib/libopencv_imgproc.so.3.4.0 ../../lib/libopencv_core.so.3.4.0 ../../lib/libopencv_cudev.so.3.4.0 
../../lib/libopencv_core.so.3.4.0: undefined reference to `cblas_zgemm'
../../lib/libopencv_core.so.3.4.0: undefined reference to `cblas_sgemm'
../../lib/libopencv_core.so.3.4.0: undefined reference to `cblas_dgemm'
../../lib/libopencv_core.so.3.4.0: undefined reference to `cblas_cgemm'
make[2]: *** [modules/hdf/CMakeFiles/example_hdf_create_groups.dir/build.make:102: bin/example_hdf_create_groups] Error 1
make[2]: Leaving directory '/home/tobias/builds/opencv-cuda-git/src/opencv/build'
make[1]: *** [CMakeFiles/Makefile2:2523: modules/hdf/CMakeFiles/example_hdf_create_groups.dir/all] Error 2
make[1]: Leaving directory '/home/tobias/builds/opencv-cuda-git/src/opencv/build'
make: *** [Makefile:163: all] Error 2

My previous search suggested that this error might occur due to a linking error with cublas. Therefore I tried to add -L/opt/cuda/lib64 and -lcublas to CMAKE_CXX_FLAGS. That made no difference at all.

Suggestions by another blog contained using gcc-6 instead of g++-6. That however yields another error:

[ 16%] Linking CXX executable ../../bin/example_hdf_create_groups
cd /home/tobias/builds/opencv-cuda-git/src/opencv/build/modules/hdf && /usr/bin/cmake -E cmake_link_script CMakeFiles/example_hdf_create_groups.dir/link.txt --verbose=1
/bin/gcc-6  -std=c++11   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -fvisibility=hidden -fvisibility-inlines-hidden -Wno-invalid-offsetof -O3 -DNDEBUG  -DNDEBUG  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now  -Wl,--gc-sections   -rdynamic CMakeFiles/example_hdf_create_groups.dir/samples/create_groups.cpp.o  -o ../../bin/example_hdf_create_groups  -L/opt/cuda/lib64 ../../lib/libopencv_hdf.so.3.4.0 ../../lib/libopencv_highgui.so.3.4.0 ../../lib/libopencv_videoio.so.3.4.0 ../../lib/libopencv_imgcodecs.so.3.4.0 ../../lib/libopencv_imgproc.so.3.4.0 ../../lib/libopencv_core.so.3.4.0 ../../lib/libopencv_cudev.so.3.4.0     
ld: CMakeFiles/example_hdf_create_groups.dir/samples/create_groups.cpp.o: undefined reference to symbol '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4'
/usr/lib/libstdc++.so.6: error adding symbols: DSO missing from command line
make[2]: *** [modules/hdf/CMakeFiles/example_hdf_create_groups.dir/build.make:102: bin/example_hdf_create_groups] Error 1
make[2]: Leaving directory '/home/tobias/builds/opencv-cuda-git/src/opencv/build'
make[1]: *** [CMakeFiles/Makefile2:2523: modules/hdf/CMakeFiles/example_hdf_create_groups.dir/all] Error 2
make[1]: Leaving directory '/home/tobias/builds/opencv-cuda-git/src/opencv/build'
make: *** [Makefile:163: all] Error 2

The whole output of the build process and the customized PKGBUILD file can be found here

Cuda version 9, output of nvidia-smi:

Sun Jan 14 14:44:13 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 387.34                 Driver Version: 387.34                    |        |-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 780 Ti  Off  | 00000000:01:00.0 N/A |                  N/A |
| 32%   27C    P8    N/A /  N/A |    624MiB /  3017MiB |     N/A      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0                    Not Supported                                       |
+-----------------------------------------------------------------------------+
  • The output suggests that you are using libblas and libcublas in parallel (one as part of a cuda-unaware lapack?). This might be a source of problems. Perhaps use objdump to search for the said symbols in both libs. – Philippos Jan 15 '18 at 12:16
  • Thanks for pointing that out! Indeed I have installed blas and cblas which ar required by other parts of my system. It seems that cblas contains the necessary symbols. I tried to additionally link it in the CMAKE_CXX_FLAGS, but that didn't change a thing. Do you have an Idea on how to proceed from there ? – tobi Jan 15 '18 at 16:08
  • I'm no cmake hero, but I'd try to get rid of the libblas dependency. There is probably some find script you can adapt so it doesn't hook on the wrong lib. Or you hide it during building opencv. But I'm really outside my knowledge scope here. This doesn't even need to be related to your problem at all. – Philippos Jan 15 '18 at 16:16
  • Thank you in any case! After countless hours I finally found the error. Cmake didn't pass the linking options down correctly. I added a linking flag to LDFLAGS and it worked. – tobi Jan 15 '18 at 20:07
5

Okay so to close the question:

The Problem was that opencv needs both Lapack with the normal blas and cblas if you are using the ceres-solver. However, the opencv build only links cublas, which apparently lacks support for some needed functions of cblas.

One solution to this Problem was to manually link cblas by adding CMAKE_EXE_LINKER_FLAGS=-lcblas to the cmake call in the PKGBUILD file.

It is probably possible to circumvent this problem altogether by building all dependencies manually with forced cublas support. However, that is tedious and not always possible since cublas is only a partial port.

Thanks again to Philippos, who helped me narrrow the problem down.

  • Shouldn't it be -lcblas instead of -cblas in the linker flags option. – razorx Apr 24 '18 at 21:24
  • If I recall correctly that does exactly the same, since I pass it to the linker anyway. – tobi Apr 24 '18 at 21:28
  • It didn't work for me though, but it worked when I added the l. – razorx Apr 24 '18 at 21:33
  • 1
    Interesting, I will double check the next days, but in any case the extra l won't do any harm, so I will update my answer accordingly. Thanks for pointing it out. – tobi Apr 24 '18 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.