centos7编译yolo-tensorrt

本文讲述了在CentOS 7环境中,如何配置OpenCV 4.1.2和TensorRT 7.2.2.3的编译过程中遇到的两个问题:FindOpenCV找不到配置文件和链接时出现的OpenCV undefined reference。解决方法包括设置环境变量OpenCV_DIR和调整find_package调用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编译环境

系统: centos7
opencv: 4.1.2
tensorrt: 7.2.2.3
cuda: 10.2
cudnn: 8.0.5

编译前准备

CMakeLists.txt文件需要添加如下行

Tensorrt的头文件
include_directories(/usr/local/TensorRT-7.2.2.3/include)
opencv的头文件
include_directories(/opencv-4.1.2/install/include/opencv4)
Tensorrt的lib文件
link_directories(/usr/local/TensorRT-7.2.2.3/targets/x86_64-linux-gnu/lib/)

添加环境变量

export OpenCV_DIR=/opencv-4.1.2/install

正式编译

进入源码目录

mkdir build

cmake …

make

编译中的问题

问题1

CMake Error at CMakeLists.txt:18 (find_package): By not providing
“FindOpenCV.cmake” in CMAKE_MODULE_PATH this project has asked CMake
to find a package configuration file provided by “OpenCV”, but CMake
did not find one.

Could not find a package configuration file provided by “OpenCV”
(requested version 4.1.2) with any of the following names:

OpenCVConfig.cmake
opencv-config.cmake

Add the installation prefix of “OpenCV” to CMAKE_PREFIX_PATH or set
“OpenCV_DIR” to a directory containing one of the above files. If
“OpenCV” provides a separate development package or SDK, be sure it
has been installed.

– Configuring incomplete, errors occurred! See also “/home/tensorrt/yolo-tensorrt/build/CMakeFiles/CMakeOutput.log”. See
also “/home/tensorrt/yolo-tensorrt/build/CMakeFiles/CMakeError.log”.

解决
将opencv的安装目录加入环境变量 OpenCV_DIR

问题2

[ 95%] Building CXX object
CMakeFiles/yolo-trt.dir/samples/sample_detector.cpp.o [100%] Linking
CXX executable yolo-trt
CMakeFiles/yolo-trt.dir/samples/sample_detector.cpp.o: In function
cv::Mat::~Mat()': sample_detector.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x89): undefined reference tocv::Mat::deallocate()’
sample_detector.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x72):
undefined reference to cv::fastFree(void*)' CMakeFiles/yolo-trt.dir/samples/sample_detector.cpp.o: In functioncv::Mat::clone() const’:
sample_detector.cpp:(.text._ZNK2cv3Mat5cloneEv[_ZNK2cv3Mat5cloneEv]+0x84):
undefined reference to cv::Mat::copyTo(cv::_OutputArray const&) const' CMakeFiles/yolo-trt.dir/samples/sample_detector.cpp.o: In functionstd::vector<cv::Mat, std::allocatorcv::Mat >::~vector()’:
sample_detector.cpp:(.text._ZNSt6vectorIN2cv3MatESaIS1_EED2Ev[_ZNSt6vectorIN2cv3MatESaIS1_EED5Ev]+0xc1):
undefined reference to cv::fastFree(void*)' sample_detector.cpp:(.text._ZNSt6vectorIN2cv3MatESaIS1_EED2Ev[_ZNSt6vectorIN2cv3MatESaIS1_EED5Ev]+0x10c): undefined reference tocv::Mat::deallocate()’
CMakeFiles/yolo-trt.dir/samples/sample_detector.cpp.o: In function
`void std::vector<cv::Mat, std::allocatorcv::Mat

::_M_realloc_insert<cv::Mat const&>(__gnu_cxx::_normal_iterator<cv::Mat*, std::vector<cv::Mat,
std::allocatorcv::Mat > >, cv::Mat const&)’:
sample_detector.cpp:(.text.ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT[ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT]+0x1bc):
undefined reference to cv::Mat::copySize(cv::Mat const&)' sample_detector.cpp:(.text._ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT_[_ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT_]+0x2a7): undefined reference tocv::Mat::copySize(cv::Mat const&)’
sample_detector.cpp:(.text.ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT[ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT]+0x384):
undefined reference to cv::fastFree(void*)' sample_detector.cpp:(.text._ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT_[_ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT_]+0x3e4): undefined reference tocv::Mat::deallocate()’
sample_detector.cpp:(.text.ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT[ZNSt6vectorIN2cv3MatESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT]+0x417):
undefined reference to cv::Mat::copySize(cv::Mat const&)' CMakeFiles/yolo-trt.dir/samples/sample_detector.cpp.o: In functionmain’: sample_detector.cpp:(.text.startup+0x13c): undefined reference
to cv::imread(std::string const&, int)' sample_detector.cpp:(.text.startup+0x184): undefined reference tocv::imread(std::string const&, int)’
sample_detector.cpp:(.text.startup+0x5be): undefined reference to
cv::putText(cv::_InputOutputArray const&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)' sample_detector.cpp:(.text.startup+0x87b): undefined reference tocv::rectangle(cv::InputOutputArray const&, cv::Rect,
cv::Scalar
const&, int, int, int)’
sample_detector.cpp:(.text.startup+0xbfb): undefined reference to
cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)' sample_detector.cpp:(.text.startup+0xca2): undefined reference tocv::waitKey(int)’ sample_detector.cpp:(.text.startup+0x100c):
undefined reference to cv::Mat::copySize(cv::Mat const&)' libdetector.so: undefined reference tocv::copyMakeBorder(cv::_InputArray const&, cv::OutputArray const&,
int, int, int, int, int, cv::Scalar
const&)’ libdetector.so:
undefined reference to cv::Mat::create(int, int const*, int)' libdetector.so: undefined reference tocv::resize(cv::_InputArray
const&, cv::OutputArray const&, cv::Size, double, double, int)’
libdetector.so: undefined reference to cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' libdetector.so: undefined reference tocv::imshow(std::string const&, cv::_InputArray const&)’
libdetector.so: undefined reference to
cv::dnn::dnn4_v20190902::blobFromImages(cv::_InputArray const&, double, cv::Size_<int>, cv::Scalar_<double> const&, bool, bool, int)' libdetector.so: undefined reference tocv::getTextSize(std::string
const&, int, double, int, int*)’ libdetector.so: undefined reference
to `cv::namedWindow(std::string const&, int)’ collect2: error: ld
returned 1 exit status make[2]: *** [yolo-trt] Error 1 make[1]: ***
[CMakeFiles/yolo-trt.dir/all] Error 2 make: *** [all] Error 2

解决
将set(OpenCV_DIR /opencv-4.1.2)屏蔽
使用 find_package(OpenCV 4.1.2 REQUIRED) 其中4.1.2为opencv满足的最低版本

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值