ARTICLE AD BOX
I'm having some trouble compiling programs using the opencv 4.13 libs that I manually compiled and installed. Particularly, the problem seems to be in the functions:
cv::cvtColor cv::putText cv::imshow cv::drawKeypoints cv::getOptimalNewCameraMatrix cv::initUndistortRectifyMapExample of a program with undefined reference to cv::imshow:
#include <iostream> #include <string> #include <opencv4/opencv2/opencv.hpp> #include "opencv4/opencv2/highgui.hpp" int main(){ std::cout << "OpenCV version : " << CV_VERSION << std::endl; std::cout << "Major version : " << CV_MAJOR_VERSION << std::endl; std::cout << "Minor version : " << CV_MINOR_VERSION << std::endl; std::cout << "Subminor version : " << CV_SUBMINOR_VERSION << std::endl; cv::Mat matrix; matrix = cv::imread("./pc.jpeg", cv::IMREAD_COLOR_BGR); std::string winName = "Test window"; cv::namedWindow(winName, cv::WINDOW_AUTOSIZE); cv::imshow(winName, matrix); int k = cv::waitKey(0); cv::destroyWindow(winName); return 0; }And to compile:
# Define variables for compiler and source files CC = g++ CFLAGS = -Wall -Wextra TARGET = main OBJECTS = main.o D_CPPFLAGS := -MMD -MP -g -std=c++2a -w # Default target: build the executable from object files $(TARGET): $(OBJECTS) $(CC) $(OBJECTS) -o $(TARGET) -L/usr/local/lib -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_core -lopencv_videoio -lopencv_features2d # Rule to build object files from source files (using implicit rules) # Make knows how to build .o from .c using the CC and CFLAGS variables main.o: main.cpp g++ -I/usr/local/include/opencv4/ -MMD -MP -g -std=c++2a -w -c $< -o $@ # Phony target for cleaning up generated files .PHONY: clean clean: rm -f $(TARGET) $(OBJECTS)The compilation result is:
g++ main.o -o main -L/usr/local/lib -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_core -lopencv_videoio -lopencv_features2d /usr/bin/ld: main.o: in function `main': /home/slam/posdoc_slam/test_opencv/main.cpp:20:(.text+0x1fd): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)' collect2: error: ld returned 1 exit status make: *** [Makefile:11: main] Error 1Below is the cmake output for the OpenCV compilation:
Detected processor: x86_64 Looking for ccache - found (/usr/bin/ccache) Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources OpenJPEG: VERSION = 2.5.3, BUILD = opencv-4.13.0-openjp2-2.5.3 OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.3") found Intel IPP (ICV version): 2022.2.0 [2022.2.0] at: /home/slam/Documents/opencv_contrib-4.13.0/3rdparty/ippicv/ippicv_lnx/icv found Intel IPP Integration Wrappers sources: 2022.2.0 at: /home/slam/Documents/opencv_contrib-4.13.0/3rdparty/ippicv/ippicv_lnx/iw Found OpenBLAS package OpenBLAS_LIBRARIES=/usr/lib/x86_64-linux-gnu/openblas-pthread//libopenblas.so OpenBLAS_INCLUDE_DIRS=/usr/include/x86_64-linux-gnu/openblas-pthread/ LAPACK(OpenBLAS): LAPACK_LIBRARIES: /usr/lib/x86_64-linux-gnu/openblas-pthread//libopenblas.so CMake Warning at cmake/OpenCVFindLAPACK.cmake:60 (message): LAPACK(OpenBLAS): CBLAS/LAPACK headers are not found in '/usr/include/x86_64-linux-gnu/openblas-pthread/' Call Stack (most recent call first): cmake/OpenCVFindLAPACK.cmake:190 (ocv_lapack_check) CMakeLists.txt:818 (include) Could NOT find Atlas (missing: Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY) LAPACK(LAPACK/Generic): LAPACK_LIBRARIES: /usr/lib/x86_64-linux-gnu/libmkl_intel_lp64.so;/usr/lib/x86_64-linux-gnu/libmkl_intel_thread.so;/usr/lib/x86_64-linux-gnu/libmkl_core.so;/usr/lib/x86_64-linux-gnu/libiomp5.so;-lm;-ldl;-lm;-ldl LAPACK(LAPACK/Generic): Can't build LAPACK check code. This LAPACK version is not supported. VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file Checking for module 'gtkglext-1.0' Package 'gtkglext-1.0', required by 'virtual:world', not found Checking for module 'libavdevice' Package 'libavdevice', required by 'virtual:world', not found CMake Warning (dev) at modules/videoio/cmake/detect_realsense.cmake:28 (set): Cannot set "HAVE_LIBREALSENSE": current scope has no parent. Call Stack (most recent call first): modules/videoio/cmake/init.cmake:7 (include) modules/videoio/cmake/init.cmake:21 (add_backend) cmake/OpenCVModule.cmake:298 (include) cmake/OpenCVModule.cmake:361 (_add_modules_1) cmake/OpenCVModule.cmake:408 (ocv_glob_modules) CMakeLists.txt:1097 (ocv_register_modules) This warning is for project developers. Use -Wno-dev to suppress it. Allocator metrics storage type: 'long long' Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.lasx.cpp Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp Excluding from source files list: modules/imgproc/src/resize.lasx.cpp Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/slam/Documents/opencv-4.13.0/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake opencv_dnn: filter out cuda4dnn source code Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.neon.cpp Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.sve.cpp Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.rvv.cpp Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.neon.cpp Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.neon.cpp Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.neon_fp16.cpp Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.rvv.cpp Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.lasx.cpp Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.neon.cpp Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.lasx.cpp highgui: using builtin backend: GTK3 Set Cleaners to True Use autogenerated whitelist /home/slam/Documents/opencv_contrib-4.13.0/modules/js_bindings_generator/whitelist.json Found 'misc' Python modules from /home/slam/Documents/opencv-4.13.0/modules/python/package/extra_modules Found 'mat_wrapper;utils' Python modules from /home/slam/Documents/opencv-4.13.0/modules/core/misc/python/package Found 'gapi' Python modules from /home/slam/Documents/opencv-4.13.0/modules/gapi/misc/python/package Found 'misc' Python modules from /home/slam/Documents/opencv-4.13.0/modules/python/package/extra_modules Found 'mat_wrapper;utils' Python modules from /home/slam/Documents/opencv-4.13.0/modules/core/misc/python/package Found 'gapi' Python modules from /home/slam/Documents/opencv-4.13.0/modules/gapi/misc/python/package General configuration for OpenCV 4.13.0 ===================================== Version control: unknown Platform: Timestamp: 2026-01-13T16:47:05Z Host: Linux 6.14.0-37-generic x86_64 CMake: 3.28.3 CMake generator: Unix Makefiles CMake build tool: /usr/bin/gmake Configuration: Release Algorithm Hint: ALGO_HINT_ACCURATE CPU/HW features: Baseline: SSE SSE2 SSE3 requested: SSE3 Dispatched code generation: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX SSE4_1 (19 files): + SSSE3 SSE4_1 SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX (10 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16 AVX2 (39 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16 AVX2 FMA3 AVX512_SKX (10 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16 AVX2 FMA3 AVX_512F AVX512_COMMON AVX512_SKX C/C++: Built as dynamic libs?: YES C++ standard: 11 C++ Compiler: /usr/bin/c++ (ver 13.3.0) C++ flags (Release): --std=c++17 -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -O3 -DNDEBUG -DNDEBUG C++ flags (Debug): --std=c++17 -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -g -O0 -DDEBUG -D_DEBUG C Compiler: /usr/bin/cc C flags (Release): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse3 -fvisibility=hidden -fopenmp -O3 -DNDEBUG -DNDEBUG C flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse3 -fvisibility=hidden -fopenmp -g -O0 -DDEBUG -D_DEBUG Linker flags (Release): -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined Linker flags (Debug): -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined ccache: YES Precompiled headers: NO Extra dependencies: dl m pthread rt 3rdparty dependencies: OpenCV modules: To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc java ml objdetect photo python3 stitching ts video videoio Disabled: world Disabled by dependency: - Unavailable: python2 Applications: tests perf_tests apps Documentation: NO Non-free algorithms: YES GUI: GTK3 GTK+: YES (ver 3.24.41) OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so) VTK support: NO Media I/O: ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.3) JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80) WEBP: /usr/lib/x86_64-linux-gnu/libwebp.so (ver decoder: 0x0209, encoder: 0x020f, demux: 0x0107) AVIF: avif (ver 1.0.4) PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.43) TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.5.1) JPEG 2000: build (ver 2.5.3) OpenEXR: OpenEXR::OpenEXR (ver 3.1.5) GIF: YES HDR: YES SUNRASTER: YES PXM: YES PFM: YES Video I/O: FFMPEG: YES avcodec: YES (60.31.102) avformat: YES (60.16.100) avutil: YES (58.29.100) swscale: YES (7.5.100) avdevice: NO GStreamer: YES (1.24.2) v4l/v4l2: YES (linux/videodev2.h) Intel RealSense: YES (2.57.5) Orbbec: YES Parallel framework: OpenMP Trace: YES (with Intel ITT(3.25.4)) Other third-party libraries: Intel IPP: 2022.2.0 [2022.2.0] at: /home/slam/Documents/opencv_contrib-4.13.0/3rdparty/ippicv/ippicv_lnx/icv Intel IPP IW: sources (2022.2.0) at: /home/slam/Documents/opencv_contrib-4.13.0/3rdparty/ippicv/ippicv_lnx/iw VA: YES Lapack: NO Eigen: YES (ver 5.0.0) Custom HAL: YES (ipp (ver 0.0.1)) Protobuf: build (3.19.1) Flatbuffers: builtin/3rdparty (25.9.23) Vulkan: YES Include path: /home/slam/Documents/opencv-4.13.0/3rdparty/include Link libraries: Dynamic load OpenCL: YES (INTELVA) Include path: /home/slam/Documents/opencv-4.13.0/3rdparty/include/opencl/1.2 Link libraries: Dynamic load Python 3: Interpreter: /usr/bin/python3 (ver 3.12.3) Libraries: /usr/lib/x86_64-linux-gnu/libpython3.12.so (ver 3.12.3) Limited API: NO numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.26.4) install path: lib/python3.12/dist-packages/cv2/python-3.12 Python (for build): /usr/bin/python3 Java: ant: NO Java: YES (ver 21.0.9) JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include Java wrappers: YES (JAVA) Java tests: NO Install to: /usr/local ----------------------------------------------------------------- Configuring done (1.8s) Generating done (0.2s)A few things that I already tried:
I printed the OpenCV version when a C++ compilation program was successfull, it was 4.13 I removed all other opencv libs from the system I am feeding the g++ the correct addresses to link: -L/usr/local/lib/ -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lboost_program_options (I did check and all libs were there)If anyone can at least help with some suggestion of what might be wrong, I will be very thankful.
On a personal note, this is not my first time compiling OpenCV. On the contrary actually, I started compiling it since 2.4 and it really looks like it became almost impossible to correctly turn off features that you dont want / does not need while not breaking something in the process. I'm in a notebook with a 5080, and it was rough to compile with all the CUDA crap.
