OpenCV 2.3编译问题 – Undefined Refence – Ubuntu 11.10

提前感谢任何帮助…

系统信息:Ubuntu 11.10(64位)与OpenCV 2.3(今天安装)

我想在OpenCV 2.3中编译一些非常简单的代码,但是我得到一个奇怪的错误。

#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> int main(){ cv::Mat image=cv::imread("img.jpg"); cv::namedWindow("My Image"); cv::imshow("My Image",image); cv::waitKey(0); return 1; } 

whateverrrrrrrrrrrrr,我收到这些错误消息…

 -SG41:~/Desktop$ g++ `pkg-config opencv --cflags --libs` -o test_1 test_1.cpp /tmp/ccCvS1ys.o: In function `main': test_1.cpp:(.text+0x44): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' test_1.cpp:(.text+0x8e): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' test_1.cpp:(.text+0xbc): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' test_1.cpp:(.text+0xf0): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)' test_1.cpp:(.text+0x112): undefined reference to `cv::waitKey(int)' /tmp/ccCvS1ys.o: In function `cv::Mat::~Mat()': test_1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)' /tmp/ccCvS1ys.o: In function `cv::Mat::release()': test_1.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()' collect2: ld returned 1 exit status 

我猜测至less有一些在输出中的库

 pkg-config opencv --libs 

是档案库。 将归档库放在需要它们的源之前是不正确的(本例中为test_1.cpp ):链接线上的源和库的顺序很重要 。

尝试

 g++ -o test_1 test_1.cpp `pkg-config opencv --cflags --libs` 

我有同样的问题,但我发现了pkg-config opencv –cflags打印“-I / usr / include / opencv”,而不是“-I / usr / include / opencv2”…也许是一个包错误Ubuntu的?

我正在使用cmake并有类似的问题。

奇怪的事情正在与cmakeconfiguration文件进行。

对于我来说,只需将OPENCV_FOUND设置为TRUE,将OpenCV_FOUND设置为TRUE即可解决问题。

另外,我必须将OpenCV_DIR设置为/ usr / local / share / OpenCV。

参见configurationopencv的CMake错误

@EmployedRussian的答案也为我工作。 对于那些想知道如何在Eclipse中指定这个命令的人来说,

https://www.eclipse.org/forums/index.php?t=msg&goto=233377&;

而不是添加gtk +,使用opencv; 在“项目 – >右键单击 – >属性 – > C / C ++编译 – >设置 – > GCC C ++链接器”中,在$ {INPUT}后面的末尾添加新的标志,而不是添加新的标志到'杂项链接器标志' >专家设置:命令行模式