ARTICLE AD BOX
Using the files that I got below I'm encountering some weird errors, since without Cmake (in another PC, using a custom makefile) the compilation runs file.
This is the main.cpp file
#include <iostream> #include <string> #include <opencv4/opencv2/opencv.hpp> #include <opencv4/opencv2/opencv.hpp> #include "opencv4/opencv2/highgui.hpp" #include <boost/program_options.hpp> namespace po = boost::program_options; int main(int ac, char** av){ std::string mode; std::string addr; po::options_description desc("Allowed options"); desc.add_options() ("help, H", "Produce help message") ("exec-mode, E", po::value<std::string>(&mode)->default_value("exec"), "Choose the option to execute") ("rootaddr, A", po::value<std::string>(&addr)->default_value("/home/ndemoura/PostDoc_Poli/ecl_workspace/KD_Tree/"), "Root address to save the logs and results") ; po::variables_map vm; po::store(po::parse_command_line(ac, av, desc), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << std::endl; return 1; } std::cout << "Test program for cmake imp" << std::endl; 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); matrix = cv::Mat(500, 600, CV_8UC3); std::string msg = "Message: testin"; cv::putText(matrix, msg, cv::Point(100, 25), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(255, 0, 0)); 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; }This is the CMakeLists.txt
cmake_minimum_required(VERSION 3.10.0) project(test_opencv VERSION 0.1.0 LANGUAGES C CXX) find_package(OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) message(STATUS " OpenCV Version: ${OpenCV_VERSION}") find_package(Boost 1.4.0 COMPONENTS program_options REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) message(STATUS " Boost Version: ${Boost_VERSION}") add_executable(test_opencv main.cpp) target_link_libraries(test_opencv PUBLIC ${OpenCV_LIBS}) target_link_libraries(test_opencv PUBLIC ${Boost_LIBRARIES})This is the output of the Cmake config
-- The C compiler identification is GNU 13.3.0 -- The CXX compiler identification is GNU 13.3.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Checking for CUDAToolkit in default location (/usr/local/cuda) -- Found CUDAToolkit: /usr/local/cuda-12.9/targets/x86_64-linux/include (found suitable exact version "12.9.86") -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success -- Found Threads: TRUE -- Found OpenCV: /usr/local (found version "4.13.0") found components: core highgui imgproc -- OpenCV Version: 4.13.0 -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.83.0/BoostConfig.cmake (found suitable version "1.83.0", minimum required is "1.83.0") found components: program_options -- Boost Version: 1.83.0 -- Configuring done (0.3s) -- Generating done (0.0s) -- Build files have been written to: /home/slam/posdoc_slam/test_opencvAnd finally, the errors in compilation that I am talking about, concerning the boost:program_options component:
/usr/bin/ld: CMakeFiles/test_opencv.dir/main.cpp.o: in function `boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)': main.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcEC2EiPKPKc[_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc]+0xad): undefined reference to `boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)' /usr/bin/ld: CMakeFiles/test_opencv.dir/main.cpp.o:(.data.rel.ro._ZTVN5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEE[_ZTVN5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEE]+0x38): undefined reference to `boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const' /usr/bin/ld: CMakeFiles/test_opencv.dir/main.cpp.o: in function `boost::program_options::typed_value<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char>::xparse(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) const': main.cpp:(.text._ZNK5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcE6xparseERNS_3anyERKNSt7__debug6vectorIS7_SaIS7_EEE[_ZNK5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcE6xparseERNS_3anyERKNSt7__debug6vectorIS7_SaIS7_EEE]+0x82): undefined reference to `boost::program_options::validate(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int)' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/test_opencv.dir/build.make:167: test_opencv] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test_opencv.dir/all] Error 2 make: *** [Makefile:91: all] Error 2Any help?
EDIT: As suggested by @dewaffled here it is the output of the make with verbose=1; I put the boost lib import part in bold
/usr/bin/cmake -S/home/slam/posdoc_slam/test_opencv -B/home/slam/posdoc_slam/test_opencv --check-build-system CMakeFiles/Makefile.cmake 0 /usr/bin/cmake -E cmake_progress_start /home/slam/posdoc_slam/test_opencv/CMakeFiles /home/slam/posdoc_slam/test_opencv//CMakeFiles/progress.marks make -f CMakeFiles/Makefile2 all make[1]: Entering directory '/home/slam/posdoc_slam/test_opencv' make -f CMakeFiles/test_opencv.dir/build.make CMakeFiles/test_opencv.dir/depend make[2]: Entering directory '/home/slam/posdoc_slam/test_opencv' cd /home/slam/posdoc_slam/test_opencv && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/slam/posdoc_slam/test_opencv /home/slam/posdoc_slam/test_opencv /home/slam/posdoc_slam/test_opencv /home/slam/posdoc_slam/test_opencv /home/slam/posdoc_slam/test_opencv/CMakeFiles/test_opencv.dir/DependInfo.cmake "--color=" make[2]: Leaving directory '/home/slam/posdoc_slam/test_opencv' make -f CMakeFiles/test_opencv.dir/build.make CMakeFiles/test_opencv.dir/build make[2]: Entering directory '/home/slam/posdoc_slam/test_opencv' [ 50%] Building CXX object CMakeFiles/test_opencv.dir/main.cpp.o /usr/bin/c++ -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_NO_LIB -D_GLIBCXX_DEBUG -isystem /usr/local/include/opencv4 -MD -MT CMakeFiles/test_opencv.dir/main.cpp.o -MF CMakeFiles/test_opencv.dir/main.cpp.o.d -o CMakeFiles/test_opencv.dir/main.cpp.o -c /home/slam/posdoc_slam/test_opencv/main.cpp [100%] Linking CXX executable test_opencv /usr/bin/cmake -E cmake_link_script CMakeFiles/test_opencv.dir/link.txt --verbose=1 /usr/bin/c++ CMakeFiles/test_opencv.dir/main.cpp.o -o test_opencv -Wl,-rpath,/usr/local/lib /usr/local/lib/libopencv_highgui.so.4.13.0 /usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.83.0 /usr/local/lib/libopencv_videoio.so.4.13.0 /usr/local/lib/libopencv_imgcodecs.so.4.13.0 /usr/local/lib/libopencv_imgproc.so.4.13.0 /usr/local/lib/libopencv_core.so.4.13.0 /usr/local/lib/libopencv_cudev.so.4.13.0 /usr/bin/ld: CMakeFiles/test_opencv.dir/main.cpp.o: in function `boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)': main.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcEC2EiPKPKc[_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc]+0xad): undefined reference to `boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)' /usr/bin/ld: CMakeFiles/test_opencv.dir/main.cpp.o:(.data.rel.ro._ZTVN5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEE[_ZTVN5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEE]+0x38): undefined reference to `boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const' /usr/bin/ld: CMakeFiles/test_opencv.dir/main.cpp.o: in function `boost::program_options::typed_value<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char>::xparse(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) const': main.cpp:(.text._ZNK5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcE6xparseERNS_3anyERKNSt7__debug6vectorIS7_SaIS7_EEE[_ZNK5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcE6xparseERNS_3anyERKNSt7__debug6vectorIS7_SaIS7_EEE]+0x82): undefined reference to `boost::program_options::validate(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int)' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/test_opencv.dir/build.make:104: test_opencv] Error 1 make[2]: Leaving directory '/home/slam/posdoc_slam/test_opencv' make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test_opencv.dir/all] Error 2 make[1]: Leaving directory '/home/slam/posdoc_slam/test_opencv' make: *** [Makefile:91: all] Error 2