OpenCV2代码链接错误 我尝试在Ubuntu 16.04上用OpenCV C++编写HOG特征检测的简单演示

OpenCV2代码链接错误 我尝试在Ubuntu 16.04上用OpenCV C++编写HOG特征检测的简单演示 ,c++,opencv,linkage,C++,Opencv,Linkage,我得到以下错误 /tmp/cctllC37.o: In function `main': hog.cpp:(.text+0x38): undefined reference to `cv::VideoCapture::VideoCapture(int)' hog.cpp:(.text+0x65): undefined reference to `cv::VideoCapture::set(int, double)' hog.cpp:(.text+0x92): undefined referenc

我得到以下错误

/tmp/cctllC37.o: In function `main':
hog.cpp:(.text+0x38): undefined reference to `cv::VideoCapture::VideoCapture(int)'
hog.cpp:(.text+0x65): undefined reference to `cv::VideoCapture::set(int, double)'
hog.cpp:(.text+0x92): undefined reference to `cv::VideoCapture::set(int, double)'
hog.cpp:(.text+0xa1): undefined reference to `cv::VideoCapture::isOpened() const'
hog.cpp:(.text+0xdc): undefined reference to `cv::HOGDescriptor::getDefaultPeopleDetector()'
hog.cpp:(.text+0x10e): undefined reference to `cv::HOGDescriptor::setSVMDetector(cv::_InputArray const&)'
hog.cpp:(.text+0x15b): undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
hog.cpp:(.text+0x17e): undefined reference to `cv::VideoCapture::operator>>(cv::Mat&)'
hog.cpp:(.text+0x23b): undefined reference to `cv::HOGDescriptor::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, cv::Size_<int>, cv::Size_<int>, double, double, bool) const'
hog.cpp:(.text+0x51e): undefined reference to `cv::rectangle(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
hog.cpp:(.text+0x545): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
hog.cpp:(.text+0x588): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
hog.cpp:(.text+0x5b0): undefined reference to `cv::waitKey(int)'
hog.cpp:(.text+0x637): undefined reference to `cv::VideoCapture::~VideoCapture()'
hog.cpp:(.text+0x71f): undefined reference to `cv::VideoCapture::~VideoCapture()'
/tmp/cctllC37.o: In function `cv::Mat::~Mat()':
hog.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cctllC37.o: In function `cv::Mat::release()':
hog.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()'
/tmp/cctllC37.o: In function `cv::HOGDescriptor::HOGDescriptor()':
hog.cpp:(.text._ZN2cv13HOGDescriptorC2Ev[_ZN2cv13HOGDescriptorC5Ev]+0xd): undefined reference to `vtable for cv::HOGDescriptor'
/tmp/cctllC37.o: In function `cv::HOGDescriptor::~HOGDescriptor()':
hog.cpp:(.text._ZN2cv13HOGDescriptorD2Ev[_ZN2cv13HOGDescriptorD5Ev]+0xd): undefined reference to `vtable for cv::HOGDescriptor'
/tmp/cctllC37.o: In function `cv::_InputArray::_InputArray<float>(std::vector<float, std::allocator<float> > const&)':
hog.cpp:(.text._ZN2cv11_InputArrayC2IfEERKSt6vectorIT_SaIS3_EE[_ZN2cv11_InputArrayC5IfEERKSt6vectorIT_SaIS3_EE]+0x11): undefined reference to `vtable for cv::_InputArray'
collect2: error: ld returned 1 exit status
/tmp/cctllC37.o:在函数“main”中:
hog.cpp:(.text+0x38):对“cv::VideoCapture::VideoCapture(int)”的未定义引用
hog.cpp:(.text+0x65):对“cv::VideoCapture::set(int,double)”的未定义引用
hog.cpp:(.text+0x92):对“cv::VideoCapture::set(int,double)”的未定义引用
hog.cpp:(.text+0xa1):对“cv::VideoCapture::Ispened()const”的未定义引用
hog.cpp:(.text+0xdc):对“cv::HOGDescriptor::getDefaultPeopleDetector()”的未定义引用
hog.cpp:(.text+0x10e):对“cv::HOGDescriptor::SetSVMDetor(cv:_InputArrayconst&)”的未定义引用
hog.cpp:(.text+0x15b):对“cv::namedWindow(std::_cxx11::basic_string const&,int)”的未定义引用
hog.cpp:(.text+0x17e):对“cv::VideoCapture::operator>>(cv::Mat&)”的未定义引用
hog.cpp:(.text+0x23b):未定义对“cv::HOGDescriptor::detectMultiScale(cv::Mat const&,std::vector&,double,cv::Size,cv::Size,double,double,bool)const”的引用
hog.cpp:(.text+0x51e):对“cv::rectangle(cv::Mat&,cv::Point,cv::Point,cv::Scalar_uu,const&,int,int)”的未定义引用
hog.cpp:(.text+0x545):对“cv::_InputArray::_InputArray(cv::Mat const&)”的未定义引用
hog.cpp:(.text+0x588):对“cv::imshow(std:uucxx11::basic_string const&,cv:_inputarrayconst&)”的未定义引用
hog.cpp:(.text+0x5b0):对“cv::waitKey(int)”的未定义引用
hog.cpp:(.text+0x637):对“cv::VideoCapture::~VideoCapture()”的未定义引用
hog.cpp:(.text+0x71f):对“cv::VideoCapture::~VideoCapture()”的未定义引用
/tmp/cctllC37.o:在函数“cv::Mat::~Mat()”中:
hog.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39):未定义对“cv::fastFree(void*)”的引用
/tmp/cctllC37.o:在函数'cv::Mat::release()'中:
hog.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47):对'cv::Mat::deallocate()的未定义引用
/tmp/cctllC37.o:在函数'cv::HOGDescriptor::HOGDescriptor()'中:
hog.cpp:(.text._zn2cv13日志描述符rc2ev[_zn2cv13日志描述符rc5ev]+0xd):对“vtable for cv::HOGDescriptor”的未定义引用
/tmp/cctllC37.o:在函数'cv::HOGDescriptor::~HOGDescriptor()'中:
hog.cpp:(.text._zn2cv13ogdescriptord2ev[_zn2cv13ogdescriptord5ev]+0xd):未定义对“vtable for cv::hogsdescriptor”的引用
/tmp/cctllC37.o:在函数'cv::_InputArray::_InputArray(std::vector const&')中:
hog.cpp:(.text.ZN2cv11_InputArray2FeerkT6Vectorit_SaIS3_EE[ZN2cv11_InputArray5IfeerksT6Vectorit_SaIS3_EE]+0x11):未定义对“cv的vtable:InputArray”的引用
collect2:错误:ld返回了1个退出状态
我尝试使用不同的编译器标志,但似乎没有任何效果。 我已经安装了所有可以在默认Ubuntu repo中找到的openCV软件包。

尝试使用“-Lpath”编译器标志告诉链接器库的安装位置,如果它们不是通常的/usr/lib等


确保系统中存在所有库。

您的链接错误意味着编译器找不到
OpenCV
的标题。因此,您应该告诉编译器您的
OpenCV
安装在哪里。例如:

g++ -std=c++11 test.cpp \
-I/home/xxx/Programs/OpenCV/shared_world/include/opencv \
-I/home/xxx/Programs/OpenCV/shared_world/include \
-L/home/xxx/Programs/OpenCV/shared_world/lib -lopencv_world 

顺便说一句,我自己用
OpenCV.pc
安装和环境设置编译和安装了
OpenCV

编译和运行OpenCV程序时,我只使用以下行:

g++ -std=c++11 test.cpp `pkg-config --cflags --libs opencv`  -o main && ./main

你百分之百确定图书馆的顺序正确吗?如果没有,请将所有
-l
标志放入
-Wl,--start组-Wl,--端组
部分。
g++ -std=c++11 test.cpp \
-I/home/xxx/Programs/OpenCV/shared_world/include/opencv \
-I/home/xxx/Programs/OpenCV/shared_world/include \
-L/home/xxx/Programs/OpenCV/shared_world/lib -lopencv_world 
g++ -std=c++11 test.cpp `pkg-config --cflags --libs opencv`  -o main && ./main