提问人:rnso 提问时间:10/24/2022 最后编辑:Christoph Rackwitzrnso 更新时间:10/24/2022 访问量:52
使用 Opencv4 编译但不编译链接的代码 - 找不到 Mat 和 imshow
Code with Opencv4 compiles but not links- not finding Mat and imshow
问:
我正在尝试创建从这里获取的以下代码的可执行文件:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
using namespace cv;
using namespace std;
// Driver code
int main(int argc, char** argv)
{
// Read the image file as // imread("default.jpg");
Mat image = imread("barchart.png", IMREAD_GRAYSCALE);
// Error Handling
if (image.empty()) {
cout << "Image File Not Found" << endl;
// wait for any key press
cin.get();
return -1;
}
// Show Image inside a window with the name provided
imshow("Window Name", image);
// Wait for any keystroke
waitKey(0);
return 0;
}
它使用命令编译所有内容并创建一个文件g++ showimage.cpp -c -I /usr/include/opencv4
showimage.o
但是,以下命令链接它会产生错误:
g++ showimage.o -l:libopencv_imgcodecs.a
...
... (lot of output)
/usr/bin/ld: showimage.o: in function `main':
showimage.cpp:(.text+0x83): undefined reference to `cv::Mat::empty() const'
/usr/bin/ld: showimage.cpp:(.text+0x10e): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/usr/bin/ld: showimage.cpp:(.text+0x13c): undefined reference to `cv::waitKey(int)'
/usr/bin/ld: showimage.cpp:(.text+0x150): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: showimage.cpp:(.text+0x1c2): undefined reference to `cv::Mat::~Mat()'
collect2: error: ld returned 1 exit status
我还尝试了以下选项:
g++ showimage.o -L /usr/lib/x86_64-linux-gnu
g++ showimage.o -L libopencv
g++ showimage.o -L opencv
但没有一个是行不通的。
问题出在哪里,如何解决?
答: 暂无答案
评论
libopencv_imgcodecs.a
是不够的。-L /usr/lib/x86_64-linux-gnu