linux 中OpenCV 的编译。

qianjide 2011-12-10 04:36:45
linux下Opencv的简单程序:

#include "highgui.h"
using namespace cv;

int main (int argc, char const* argv[])
{
Mat src;
src=imread("lena.jpg");
namedWindow("src");
imshow("src",src);
waitKey(0);
return 0;
}

编译方法:
1、 g++ test.cpp `pkg-config opencv --libs --cflags opencv` 编译没问题,正确。也能够执行
2、 g++ `pkg-config opencv --libs --cflags opencv` test.cpp 编译错误,不成功。
错误提示:

tmp/ccI1amzW.o: In function `main':
test.cpp:(.text+0x5e): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text+0xcf): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text+0xfa): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
test.cpp:(.text+0x131): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
test.cpp:(.text+0x153): undefined reference to `cv::waitKey(int)'
/tmp/ccI1amzW.o: In function `cv::Mat::~Mat()':
test.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x2b): undefined reference to `cv::fastFree(void*)'
/tmp/ccI1amzW.o: In function `cv::Mat::operator=(cv::Mat const&)':
test.cpp:(.text._ZN2cv3MataSERKS0_[cv::Mat::operator=(cv::Mat const&)]+0xf2): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccI1amzW.o: In function `cv::Mat::release()':
test.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x3b): undefined reference to `cv::Mat::deallocate()'
collect2: ld 返回 1

请指点。
...全文
105 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
freetstar 2011-12-10
  • 打赏
  • 举报
回复

2,161

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 UNIX文化
社区管理员
  • UNIX文化社区
  • 文天大人
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧