我需要从一个ubuntu20.04切换到一个Windows 7工作站。
我正在为Raspberry PI编写一个程序,它需要线程,所以我需要一个linux测试环境。
我安装了一个ubuntu20.04VM,并重新安装了我的程序中使用的所有库:
4.2
这是我的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 2TLDR :
与OpenCV的连接问题。
有什么想法吗?
发布于 2020-06-18 11:05:48
多亏了@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试着重新建立这个项目,这应该是可行的!
再来一次吧!
https://stackoverflow.com/questions/62431359
复制相似问题