OpenCV 2.3编译问题 - 未定义的Refence - Ubuntu 11.10 [英] OpenCV 2.3 Compiling Issue - Undefined Refence - Ubuntu 11.10

查看:372
本文介绍了OpenCV 2.3编译问题 - 未定义的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;
}

couldrrrrrrrrrrrr,我收到这些错误消息...

  -SG41:〜/ Desktop $ g ++`pkg-config opencv --cflags --libs`-o test_1 test_1.cpp 
/tmp/ccCvS1ys.o:在函数main中:
test_1.cpp :( .text + 0x44):未定义引用`cv :: imread(std :: basic_string< char,std :: char_traits< char> ; std :: allocator< char>> const& int)'
test_1.cpp :( .text + 0x8e):未定义引用`cv :: namedWindow(std :: basic_string& :char_traits< char>,std :: allocator< char>> const& int,'
test_1.cpp :(文本+ 0xbc):未定义的引用`cv :: _ InputArray :: _ InputArray :mat const&)'
test_1.cpp :(。text + 0xf0):未定义的引用`cv :: imshow(std :: basic_string< char,std :: char_traits< char>,std :: allocator< char>> const& cv :: _ InputArray const&)'
test_1.cpp :(。text + 0x112):未定义引用`cv :: waitKey(int)'
/ tmp / ccCvS1ys .o:在函数`cv :: Mat ::` Mat()':
test_1.cpp :( .text._ZN2cv3MatD2Ev [_ZN2cv3MatD5Ev] + 0x39):未定义引用`cv :: fastFree '
/tmp/ccCvS1ys.o:在函数`cv :: Mat :: release()':
test_1.cpp :(。text._ZN2cv3Mat7releaseEv [cv :: Mat :: release()] + 0x47):未定义引用`cv :: Mat :: deallocate()'
collect2:ld返回1退出状态

$ b $我猜在

的输出中至少有一些库是   pkg-config opencv --libs 

是归档库。将归档库放在需要它们的源之前是不正确的( test_1.cpp 在这种情况下):链接行上的源和库的顺序

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


Thanks in advance for any help...

System Info: Ubuntu 11.10 (64 bits) with OpenCV 2.3 (installed today)

I'm trying to compile some very simple code in OpenCV 2.3 but I'm getting a weird error.

#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;
}

howeverrrrrrrrrrrrr, I'm getting these error messages...

-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

解决方案

I am guessing that at least some of the libraries in the output of

pkg-config opencv --libs

are archive libraries. It is incorrect to put archive libraries before sources that need them (test_1.cpp in this case): the order of sources and libraries on the link line matters.

Try

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

这篇关于OpenCV 2.3编译问题 - 未定义的Refence - Ubuntu 11.10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆