【发布时间】:2023-04-02 17:38:01
【问题描述】:
我已经安装了opencv2。
pkg-config --modversion opencv
2.4.13.5
我正在使用下面的代码,
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, const char *argv[])
{
VideoCapture vid(0);
if(!vid.isOpened()){
cout<<"Camera could not load..."<<endl;
return -1;
}
namedWindow("webcam",CV_WINDOW_AUTOSIZE);
while(1){
Mat frame;
bool ctrl = vid.read(frame);
imshow("webcam",frame);
if(waitKey(0) == 27){
cout<<"The app is ended..."<<endl;
break;
}
}
return 0;
}
我使用 g++ image_writer.cpp 编译
/tmp/ccPWmgA0.o: 在函数
main': image_writer.cpp:(.text+0x38): undefined reference tocv::VideoCapture::VideoCapture(int)' image_writer.cpp:(.text+0x47): 未定义引用cv::VideoCapture::isOpened() const' image_writer.cpp:(.text+0xac): undefined reference tocv::namedWindow(std::__cxx11::basic_string, std::allocator > const&, int)' image_writer.cpp:(.text+0xe9): 未定义引用cv::VideoCapture::read(cv::Mat&)' image_writer.cpp:(.text+0x105): undefined reference tocv::_InputArray::_InputArray(cv::Mat const&)' image_writer.cpp:(.text+0x148): 未定义引用cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)' image_writer.cpp:(.text+0x170): undefined reference tocv::waitKey(int)' image_writer.cpp:(.text+0x1cd): 未定义引用cv::VideoCapture::~VideoCapture()' image_writer.cpp:(.text+0x254): undefined reference tocv::VideoCapture::~VideoCapture()' /tmp/ccPWmgA0.o: 在函数cv::Mat::~Mat()': image_writer.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference tocv::fastFree(void*)' /tmp/ccPWmgA0.o:在函数cv::Mat::release()': image_writer.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference tocv::Mat::deallocate()' collect2:错误:ld 返回 1 个退出状态
我上网后发现,我必须包含lib文件
所以,我做到了。 g++ image_writer.cpp -lopencv_videoio
/usr/bin/ld: 找不到 -lopencv_videoio collect2:错误:ld 返回 1 个退出状态
我不知道如何解决这个问题。请帮我解决这个问题。任何提示都会很明显。
EDIT-1:
pkg-config --libs opencv 返回,
-L/usr/local/lib -lopencv_contrib -lopencv_stitching -lopencv_nonfree -lopencv_superres -lopencv_ocl -lopencv_ts -lopencv_videostab -lopencv_gpu -lopencv_photo -lopencv_objdetect -lopencv_legacy -lopencv_calib3d -lopencv_features2d -lopencv_highguil lQtCore -lQtTest -lQtGui -lQtOpenGL -lIlmThread -lHalf -lIex -lIlmImf -lImath -ljasper -ltiff -lpng -ljpeg -lswscale-ffmpeg -lavutil-ffmpeg -lavformat-ffmpeg -lavcodec-ffmpeg -lv4l2 -lv4l1 -ldc1394 -lgstpbutils- 0.10 -lgstriff-0.10 -lgstapp-0.10 -lgstvideo-0.10 -lxml2 -lglib-2.0 -lgthread-2.0 -lgmodule-2.0 -lgobject-2.0 -lgstreamer-0.10 -lgstbase-0.10 -lGLU -lGL -lz -latomic -ltbb - lrt -lpthread -lm -ldl -lstdc++
【问题讨论】:
-
您可以使用
pkg-config --libs opencv列出所需的链接器标志和库。 -
@Someprogrammerdude- 请查看更新后的帖子