So, I understand your comment better now. I am still having difficulty since lack of my experience in Cmake
I am using opencv3.4.19, and this is the error
/usr/bin/ld: attempted static link of dynamic object `/usr/local/lib/libopencv_highgui.so.3.4.19’
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/csrt.dir/build.make:179: csrt] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/csrt.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
Dynamic linking is working as expected, but not with static. Thanks again.
cmake_minimum_required(VERSION 3.0)
project(csrt)
# Set C++ standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Find OpenCV package
set(BUILD_SHARED_LIBS OFF)
find_package(OpenCV REQUIRED core imgproc videoio)
# Add executable
file(GLOB SRCS *.cpp)
file(GLOB HEADERS *.hpp)
add_executable(csrt ${SRCS} ${HEADERS})
# Link OpenCV libraries statically
# set(OpenCV_STATIC ON)
# target_link_libraries(csrt PRIVATE ${OpenCV_LIBS} -static -littnotify -lrt -ldl -lz -lpthread)
set(OpenCV_STATIC ON)
set(OPENCV_LIBS "/usr/local/lib/")
target_link_libraries(csrt PRIVATE ${OPENCV_LIBS}/libopencv_imgproc.a ${OPENCV_LIBS}/libopencv_videoio.a ${OPENCV_LIBS}/libopencv_highgui.a ${OPENCV_LIBS}/libopencv_core.a -static -ldl -lz -lpthread)
# Set compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -O0 -g3 -Wall")
# Install executable
install(TARGETS csrt DESTINATION bin)
Update :
Currently buidling opencv library statically.
Error I am getting.
/usr/bin/ld: cannot find -littnotify
/usr/bin/ld: /home/nile649/opencv_build/opencv/build/lib/libopencv_core.a(opencl_core.cpp.o): in function `opencl_check_fn(int)':
opencl_core.cpp:(.text._ZL15opencl_check_fni+0xe1): warning: Using ‘dlopen’ in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/csrt.dir/build.make:178: csrt] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/csrt.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
Above issues resolved, I am updating the cmake file
The current errors
- Errors regarding window_gtk.cpp
window_gtk.cpp:(.text.cvResizeWindow+0x10a): undefined reference to `gtk_window_resize’ - Errors regarding the ffmpeg
cap_ffmpeg.cpp:(.text.ZN23InputMediaStream_FFMPEG4openEPKcPiS2_S2_S2+0x9a): undefined reference to `avformat_network_init’ - Errors regarding the cap_gstreamer.cpp
cap_gstreamer.cpp:(.text._ZN2cv23CvVideoWriter_GStreamerD2Ev[_ZN2cv23CvVideoWriter_GStreamerD5Ev]+0x4d): undefined reference to `gst_object_unref’