我需要从ubuntu 20.04切换到Windows 7工作站。
我正在为需要pthread的Raspberry PI编写程序,因此我需要一个Linux测试环境。
我安装了ubuntu 20.04 VM,并重新安装了程序中使用的所有库:
这是我的CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(POC_V4)
set(CMAKE_CXX_STANDARD 14)
# Specifying we are using pthread for UNIX systems.
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS} -pthread -Wall")
find_package(OpenCV REQUIRED)
find_package(Torch REQUIRED)
if(NOT Torch_FOUND)
message(FATAL_ERROR "Pytorch Not Found!")
endif(NOT Torch_FOUND)
message(STATUS "Pytorch status :")
message(STATUS " libraries: ${TORCH_LIBRARIES}")
message(STATUS "OpenCV library status :")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
add_executable(POC_V4 <all_my_sources_and_headers>)
target_link_libraries(POC_V4 ${TORCH_LIBRARIES} ${OpenCV_LIBS})
target_link_libraries(POC_V4 pthread dl util)
在真实PC和VM上,cmake输出是相同的:
-- Pytorch status :
-- libraries: torch;torch_library;/usr/lib/libc10.so
-- OpenCV library status :
-- version: 4.2.0
-- libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_datasets;opencv_dnn_objdetect;opencv_dnn_superres;opencv_dpm;opencv_face;opencv_freetype;opencv_fuzzy;opencv_hdf;opencv_hfs;opencv_img_hash;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_quality;opencv_reg;opencv_rgbd;opencv_saliency;opencv_shape;opencv_stereo;opencv_structured_light;opencv_superres;opencv_surface_matching;opencv_text;opencv_tracking;opencv_videostab;opencv_viz;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
-- include path: /usr/include/opencv4
-- Configuring done
-- Generating done
-- Build files have been written to: <path_where_i_build>```
在我真正的Ubuntu PC上,构建可以正常工作,但是在VM上链接期间失败:
/usr/bin/ld: CMakeFiles/POC_V4.dir/src/communication.cpp.o: in function `Communication::showImage(cv::Mat, Box, std::string)':
communication.cpp:(.text+0x208): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
/usr/bin/ld: CMakeFiles/POC_V4.dir/src/communication.cpp.o: in function `Communication::showImage(cv::Mat, std::string)':
communication.cpp:(.text+0x393): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
/usr/bin/ld: CMakeFiles/POC_V4.dir/src/communication.cpp.o: in function `Communication::fps(cv::Mat, std::string)':
communication.cpp:(.text+0x655): undefined reference to `cv::putText(cv::_InputOutputArray const&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/usr/bin/ld: CMakeFiles/POC_V4.dir/src/communication.cpp.o: in function `Communication::Communication()':
communication.cpp:(.text+0x816): undefined reference to `cv::namedWindow(std::string const&, int)'
/usr/bin/ld: CMakeFiles/POC_V4.dir/src/imageGetter.cpp.o: in function `ImageGetter::ImageGetter()':
imageGetter.cpp:(.text+0x342): undefined reference to `cv::VideoCapture::VideoCapture(std::string const&, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/POC_V4.dir/build.make:285: POC_V4] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/POC_V4.dir/all] Error 2
TLDR:
OpenCV的链接问题...
有任何想法吗 ?
由于@squareskittles,我终于设法使其工作:我需要卸载OpenCV,并使用C ++ 14标准将其从源代码重建为良好版本。
如果在构建时遇到与OpenCV相关的链接问题,请卸载OpenCV并自己构建:
sudo apt remove libopencv-dev && sudo apt autoremove
cd ~/Downloads
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 4.2.0
cd ../opencv
git checkout 4.2.0
mkdir build
打开,CMakeLists.txt
然后在文件开头添加以下行:
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
然后构建OpenCV:
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib/modules/ ..
make
sudo make install
sudo ldconfig
安装可能缺少的库以进行图形输出处理。
sudo apt install libgtk2.0-dev pkg-config libcanberra-gtk-module libcanberra-gtk3-module
尝试重新构建该项目,这应该可行!
再次感谢@squareskittles!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句