I want to distribute my OpenCV source code to other users (on different OS’s). They need to compile it. Ideally in Unix/Linux there’s pkgconf which tells me what LDFLAGS (-l … -L) what CFLAGS (-I…) to use. But what happens when it is not present (case in point: OpenCV on some M$ windows).
I thought perhaps they will have CMAKE installed and use this script:
cmake_minimum_required(VERSION 3.1)
project(RUBBISH_CMAKE_PROJECT)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( _cmake_opencv_testme test.cpp )
target_link_libraries( _cmake_opencv_testme ${OpenCV_LIBS} )
message(STATUS "RUBBISH_CMAKE_PROJECT::INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "RUBBISH_CMAKE_PROJECT::LIBS: ${OpenCV_LIBS}")
message(STATUS "RUBBISH_CMAKE_PROJECT::LDFLAGS: ${OpenCV_EXTRA_COMPONENTS}")
message(STATUS "RUBBISH_CMAKE_PROJECT::CFLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "RUBBISH_CMAKE_PROJECT::CXXFLAGS: ${CMAKE_CXX_FLAGS}")
Assuming that the recipients of my code do have cmake installed on their system the above does not output anything about library location! This is what I get:
-- RUBBISH_CMAKE_PROJECT::INCLUDE_DIRS: /usr/local/include/opencv4
-- RUBBISH_CMAKE_PROJECT::LIBS: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_world;opencv_alphamat;opencv_aruco;opencv_barcode;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_cudaarithm;opencv_cudabgsegm;opencv_cudacodec;opencv_cudafeatures2d;opencv_cudafilters;opencv_cudaimgproc;opencv_cudalegacy;opencv_cudaobjdetect;opencv_cudaoptflow;opencv_cudastereo;opencv_cudawarping;opencv_cudev;opencv_datasets;opencv_dnn_objdetect;opencv_dnn_superres;opencv_dpm;opencv_face;opencv_freetype;opencv_fuzzy;opencv_hdf;opencv_hfs;opencv_img_hash;opencv_intensity_transform;opencv_line_descriptor;opencv_mcc;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_quality;opencv_rapid;opencv_reg;opencv_rgbd;opencv_saliency;opencv_sfm;opencv_shape;opencv_stereo;opencv_structured_light;opencv_superres;opencv_surface_matching;opencv_text;opencv_tracking;opencv_videostab;opencv_viz;opencv_wechat_qrcode;opencv_xfeatures2d;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
-- RUBBISH_CMAKE_PROJECT::LDFLAGS:
-- RUBBISH_CMAKE_PROJECT::CFLAGS:
-- RUBBISH_CMAKE_PROJECT::CXXFLAGS:
-- Configuring done
CMake Error at CMakeLists.txt:5 (add_executable):
Target "_cmake_opencv_testme" links to target "Eigen3::Eigen" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:5 (add_executable):
Target "_cmake_opencv_testme" links to target "Iconv::Iconv" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:5 (add_executable):
Target "_cmake_opencv_testme" links to target "Eigen3::Eigen" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:5 (add_executable):
Target "_cmake_opencv_testme" links to target "Eigen3::Eigen" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:5 (add_executable):
Target "_cmake_opencv_testme" links to target "Eigen3::Eigen" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:5 (add_executable):
Target "_cmake_opencv_testme" links to target "Eigen3::Eigen" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:5 (add_executable):
Target "_cmake_opencv_testme" links to target "Ceres::ceres" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:5 (add_executable):
Target "_cmake_opencv_testme" links to target "Eigen3::Eigen" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:5 (add_executable):
Target "_cmake_opencv_testme" links to target "Ceres::ceres" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
Additionally the above cmake run on my system, outputs a tonne of libraries but in my system OpenCV programs need only be linked to opencv_world
– I have asked this explicitly during making. In fact, I do not think I have lib opencv_highgui
because that fails:
c++ test.cpp -lopencv_highgui -I/usr/local/include/opencv4
with this error: /usr/bin/ld: cannot find -lopencv_highgui
And finally the above complains about other external libraries, well what’s their path?
CMake Error at CMakeLists.txt:5 (add_executable): Target "_cmake_opencv_testme" links to target "Eigen3::Eigen" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
So, is there a fool-proof, portable way to find out what are the complete compilation parameters for OpenCV on a foreign system I want to distribute my code assuming that OpenCV dev package is installed?