Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » How do I fix "undefined reference to `cv::cuda::..." linker errors in Eclipse?(Trying to compile/link OpenCV C++ project with CUDA in Eclipse)
How do I fix "undefined reference to `cv::cuda::..." linker errors in Eclipse? [message #1806873] Thu, 16 May 2019 20:52 Go to next message
JP C is currently offline JP CFriend
Messages: 2
Registered: May 2019
Junior Member
Disclaimer: I'm new to this whole Linux and CMake and GPU thing. But I've been using pre-built OpenCV in Windows for a few years.

I recently installed the latest versions of Ubuntu (18.04), OpenCV (4.1.0), Eclipse IDE (Version: 2019-03 (4.11.0)) and CUDA (10.1) for my new Precision 7730 with Quadro P5200. My Eclipse C++/CUDA toolchain project compiles and runs fine using just OpenCV syntax, first using a CMake build without CUDA and more recently a new CMake where I added CUDA support. I think I've followed all installation instructions properly, at least those I could find which deal with recent software versions including the CUDA 10.1 Toolkit.

But now I am trying to replace some of my cv:: functions with cv::cuda:: functions and am getting linker errors. I guess I am missing some libraries, or Eclipse is not knowing where they are. CMake appeared to make everything. What do I need to check and where do I need to look to see what's missing?

All of the solutions I've seen posted are quite old so I can't figure out how to make them apply to my problem.

Here is my Eclipse output when I build the project:

10:42:05 **** Build of configuration Release for project CS3_intfc **** make all Building file: ../src/CS3_intfc.cpp Invoking: NVCC Compiler /usr/local/cuda-10.1/bin/nvcc -I/usr/local/include/opencv4 -O3 --use_fast_math -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -ccbin g++ -c -o "src/CS3_intfc.o" "../src/CS3_intfc.cpp" Finished building: ../src/CS3_intfc.cpp

Building target: CS3_intfc Invoking: NVCC linker /usr/local/cuda-10.1/bin/nvcc --cudart=static -L/usr/local/lib -ccbin g++ -lGL -lGLU -lglut -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o "CS3_intfc" ./src/CS3_intfc.o -lopencv_core -lopencv_calib3d -lopencv_features2d -lopencv_dnn -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videoio -lopencv_videostab -lpthread ./src/CS3_intfc.o: In function main':
CS3_intfc.cpp:(.text.startup+0x561e): undefined reference tocv::cuda::subtract(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, int, cv::cuda::Stream&)' CS3_intfc.cpp:(.text.startup+0x56c1): undefined reference to cv::cuda::compare(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, cv::cuda::Stream&)'
CS3_intfc.cpp:(.text.startup+0x5768): undefined reference tocv::cuda::compare(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, int, cv::cuda::Stream&)' CS3_intfc.cpp:(.text.startup+0x5805): undefined reference to cv::cuda::add(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, int, cv::cuda::Stream&)'
CS3_intfc.cpp:(.text.startup+0x5843): undefined reference tocv::cuda::sum(cv::_InputArray const&, cv::_InputArray const&)' collect2: error: ld returned 1 exit status makefile:24: recipe for target 'CS3_intfc' failed make: *** [CS3_intfc] Error 1 "make all" terminated with exit code 2. Build might be incomplete.

10:42:09 Build Failed. 2 errors, 0 warnings. (took 4s.17ms)


Here is what I get with "echo $PATH" in a terminal:

/usr/local/cuda-10.1/bin:/usr/local/cuda-10.1/NsightCompute-2019.1:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin


Here is the output of my CMake:

Looking for ccache - not found
Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found suitable version "1.2.11", minimum required is "1.2.3") 
Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR) 
Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
Found OpenEXR: /usr/lib/x86_64-linux-gnu/libIlmImf.so
Checking for module 'gtk+-3.0'
  No package 'gtk+-3.0' found
Checking for module 'gtkglext-1.0'
  No package 'gtkglext-1.0' found
Found TBB (env): /usr/local/lib/libtbb.so
found Intel IPP (ICV version): 2019.0.0 [2019.0.0 Gold]
at: /home/jp/build/opencv/opencv/release/3rdparty/ippicv/ippicv_lnx/icv
found Intel IPP Integration Wrappers sources: 2019.0.0
at: /home/jp/build/opencv/opencv/release/3rdparty/ippicv/ippicv_lnx/iw
CUDA detected: 10.1
CUDA NVCC target flags: -gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_52,code=sm_52;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-D_FORCE_INLINES;-gencode;arch=compute_75,code=compute_75
Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
Could NOT find Atlas (missing: Atlas_CBLAS_INCLUDE_DIR Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY Atlas_LAPACK_LIBRARY) 
A library with BLAS API not found. Please specify library location.
LAPACK requires BLAS
A library with LAPACK API not found. Please specify library location.
Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
Could NOT find Pylint (missing: PYLINT_EXECUTABLE) 
Could NOT find Flake8 (missing: FLAKE8_EXECUTABLE) 
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
OpenCV Python: during development append to PYTHONPATH: /home/jp/build/opencv/opencv/release/python_loader
Caffe:   NO
Protobuf:   NO
Glog:   NO
freetype2:   YES (ver 21.0.15)
harfbuzz:    YES (ver 1.7.2)
Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS) (found version "")
Module opencv_ovis disabled because OGRE3D was not found
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Glog/Gflags
Processing WORLD modules...
    module opencv_cudev...
    module opencv_core...
    module opencv_cudaarithm...
    module opencv_flann...
    module opencv_imgproc...
    module opencv_ml...
    module opencv_phase_unwrapping...
    module opencv_plot...
    module opencv_quality...
    module opencv_reg...
    module opencv_surface_matching...
    module opencv_cudafilters...
    module opencv_cudaimgproc...
    module opencv_cudawarping...
    module opencv_dnn...
    module opencv_features2d...
    module opencv_freetype...
    module opencv_fuzzy...
    module opencv_hfs...
    module opencv_imgcodecs...
    module opencv_line_descriptor...
    module opencv_photo...
    module opencv_saliency...
    module opencv_videoio...
    module opencv_xphoto...
    module opencv_calib3d...
    module opencv_cudacodec...
    module opencv_cudafeatures2d...
    module opencv_cudastereo...
    module opencv_highgui...
    module opencv_objdetect...
    module opencv_rgbd...
    module opencv_shape...
    module opencv_structured_light...
    module opencv_text...
Checking for module 'tesseract'
  No package 'tesseract' found
Tesseract:   NO
    module opencv_video...
    module opencv_xfeatures2d...
    module opencv_ximgproc...
    module opencv_xobjdetect...
    module opencv_aruco...
    module opencv_bgsegm...
    module opencv_bioinspired...
    module opencv_ccalib...
    module opencv_cudabgsegm...
    module opencv_cudalegacy...
    module opencv_cudaobjdetect...
    module opencv_datasets...
    module opencv_dnn_objdetect...
    module opencv_dpm...
    module opencv_face...
    module opencv_optflow...
    module opencv_stitching...
    module opencv_tracking...
    module opencv_cudaoptflow...
    module opencv_stereo...
    module opencv_superres...
    module opencv_videostab...
Processing WORLD modules... DONE
Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
OpenCL samples are skipped: OpenCL SDK is required

General configuration for OpenCV 4.1.0-dev =====================================
  Version control:               4.1.0-153-gb2abd8ca4

  Extra modules:
    Location (extra):            /home/jp/build/opencv/opencv_contrib/modules
    Version control (extra):     4.1.0-26-g24cd5e21

  Platform:
    Timestamp:                   2019-05-14T23:27:39Z
    Host:                        Linux 4.18.0-18-generic x86_64
    CMake:                       3.10.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               RELEASE

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (14 files):         + SSSE3 SSE4_1
      SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (28 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (2 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/bin/c++  (ver 7.4.0)
    C++ flags (Release):         -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 -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -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 -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--gc-sections  
    Linker flags (Debug):        -Wl,--gc-sections  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab world xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    gapi
    Disabled by dependency:      -
    Unavailable:                 cnn_3dobj cvv hdf java js matlab ovis python2 python3 sfm viz
    Applications:                tests perf_tests examples apps
    Documentation:               NO
    Non-free algorithms:         YES

  GUI: 
    GTK+:                        YES (ver 2.24.32)
      GThread :                  YES (ver 2.56.4)
      GtkGlExt:                  NO
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
    JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.34)
    TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      YES (2.2.5)
    FFMPEG:                      YES
      avcodec:                   YES (57.107.100)
      avformat:                  YES (57.83.100)
      avutil:                    YES (55.78.100)
      swscale:                   YES (4.8.100)
      avresample:                YES (3.7.0)
    GStreamer:                   YES (1.14.1)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            TBB (ver 2017.0 interface 9107)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2019.0.0 Gold [2019.0.0]
           at:                   /home/jp/build/opencv/opencv/release/3rdparty/ippicv/ippicv_lnx/icv
    Intel IPP IW:                sources (2019.0.0)
              at:                /home/jp/build/opencv/opencv/release/3rdparty/ippicv/ippicv_lnx/iw
    Lapack:                      NO
    Eigen:                       YES (ver 3.3.4)
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  NVIDIA CUDA:                   YES (ver 10.1, CUFFT CUBLAS FAST_MATH)
    NVIDIA GPU arch:             30 35 37 50 52 60 61 70 75
    NVIDIA PTX archs:            75

  OpenCL:                        YES (no extra features)
    Include path:                /home/jp/build/opencv/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            /usr/bin/python2.7

  Java:                          
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /usr/local
-----------------------------------------------------------------

Configuring done
Generating done


Note I had to use "-D WITH_NVCUVID=OFF" to get around a CMake error I encountered, and this is a solution I found. Is this my problem?

My hunch is that something needs to be done in Eclipse yet, can someone please help? Thanks.
Re: How do I fix "undefined reference to `cv::cuda::..." linker errors in Eclipse? [message #1806951 is a reply to message #1806873] Sun, 19 May 2019 08:23 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
This is off topic for this forum which is for CDT issues.
Your cross-post at stackoverflow is perhaps your best bet.
Maybe better, you might try the place where you got the code

The short answer is: locate the library containing the undefined references
then inform the linker.

How to do this can be found elsewhere.
For example, to add a library to CMake google "cmake add library" or similar.
Here's one link (not vouching for it): https://stackoverflow.com/questions/24570916/add-external-libraries-to-cmakelist-txt-c




Re: How do I fix "undefined reference to `cv::cuda::..." linker errors in Eclipse? [message #1806998 is a reply to message #1806951] Mon, 20 May 2019 21:04 Go to previous message
JP C is currently offline JP CFriend
Messages: 2
Registered: May 2019
Junior Member
ok, you can actually remove this post if you like. I think I found a solution however, I wasn't aware that all the cuda operations were also contained within the opencv world binary file so including that as a library made the linker happy.
Previous Topic:catkin_make --force-cmake -G "Ecplise CDT4 - Unix Makefiles" fails
Next Topic:Best C++ IDE and Compiler?
Goto Forum:
  


Current Time: Thu Sep 19 17:27:03 GMT 2024

Powered by FUDForum. Page generated in 0.03363 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top