Ubuntu下编译一个C++文件,C++源程序中使用了opencv,opencv的安装没有问题,但是在编译的过程中出现如下错误:

undefined reference to `cv::imread(std::string const&, int)'
undefined reference to `cv::noArray()'
undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
undefined reference to `cv::waitKey(int)'
...

undefined reference to `cv::Mat::deallocate()'
...

网上查了下资料,大概说opencv的静态编译库没有链接到本程序中(也不知道对不对,望大家指正),于是找啊找啊,终于找到一个有用的,记录一下:

在terminal下运行命令: g++ getmask.cpp -o getmask `pkg-config opencv --cflags --libs` // 包含、链接参数一定要放在后面,其实就是在编译C++程序后面加上(`pkg-config opencv --cflags --libs`)

编译成功后生成getmask可执行文件,接着运行命令:./getmask 就能得到结果啦。

附上我的源程序:

#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
string img_filename;
int head_num;
int posx,posy;
cv::Point pt;
vector<Point> coordinate;
vector<vector<Point> > coordinates;
ifstream infile("scene01.txt");
Mat img = imread("scene01.jpg",);
//namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
//imshow("MyWindow", img);
//waitKey(0);
cv::Mat locMask(img.rows,img.cols,CV_8UC1,cv::Scalar());
//imshow("locMask",locMask);
while (infile >> img_filename >> head_num) {
for(int i = ; i< head_num;i++) {
infile >> posx >> posy;
pt = Point(posx,posy);
coordinate.push_back(pt);
}
coordinates.push_back(coordinate);
}
//cout<<coordinate.size()<<endl;
//cout<<coordinates.size()<<endl;
for(int i=;i<coordinates.size();i++)
cout<<coordinates[i]<<" ";
drawContours(locMask,coordinates,-,cv::Scalar::all(), CV_FILLED);
imwrite("mask01.jpg",locMask);
imshow("locMask",locMask);
waitKey();
return ;
}

我的文件截图:

版权声明:本文为博主原创文章,欢迎转载,转载请注明原文地址、作者信息。

Opencv undefined reference to `cv::imread() Ubuntu编译的更多相关文章

  1. 「caffe编译bug」.build_release/lib/libcaffe.so: undefined reference to cv::imread

    转自:https://www.douban.com/note/568788483/ CXX/LD -o .build_release/tools/convert_imageset.bin.build_ ...

  2. Opencv3.0: undefined reference to cv::imread(cv::String const&, int)

    使用opencv,编译出错: undefined reference to cv::imread(cv::String const&, int) 自opencv3.0之后,图像读取相关代码在i ...

  3. test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&, int)'

    opencv报错: test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&, int)' te ...

  4. caffe: compile error : undefined reference to `cv::imread(cv::String const&, int)' et al.

    when I compile caffe file : .build_debug/lib/libcaffe.so: undefined reference to `cv::imread(cv::Str ...

  5. undefined reference to cv::imread(cv::String const&, int)

    .build_release/lib/libcaffe-nv.so: undefined reference to cv::imread(cv::String const&, int)' .b ...

  6. error: undefined reference to `cv::imread(std::string const&, int)'

    g++ main.cpp -o main `pkg-config --libs --cflags opencv`注意--libs的位置https://stackoverflow.com/questio ...

  7. openCV中 libopencv-nonfree-dev的安装: undefined reference to `cv::initModule_nonfree()&#39;

    今天照着一起做RGB-D SLAM (3)    , 程序会出现以下的错误: cv::initModule_nonfree(); /home/yhzhao/slam/src/detectFeature ...

  8. .build_release/lib/libcaffe.so: undefined reference to `cv::VideoCapture::set(int, double)'

    CXX/LD -o .build_release/tools/convert_imageset.bin.build_release/lib/libcaffe.so: undefined referen ...

  9. undefined reference to `cv::VideoCapture

    出现opencv链接的问题原因: 1. 路径设置不正确,caffe会优先搜索Makefile.config里面的环境设置 2. anaconda2装的opencv和配置的opencv路径不一致 比如, ...

随机推荐

  1. 发布WebApi项目时包含XML文档文件

    Open your publishprofile (*.pubxml) and include this code into "Project" element: <Item ...

  2. POJ 2154 color (polya + 欧拉优化)

    Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). You ...

  3. Bamboo基础概念

    1.project     1)提供报告.展板.连接   |——2.plan       1)指定默认代码仓库(同一个仓库)       2)构建触发条件的配置       3)构建结果的发送与通知 ...

  4. 石家庄铁道大学课程信息管理系统(javaWeb+servlet+Mysql)

    实现网页版的课程管理系统,具有增删改查的功能. 1.首先连接数据库,具体数据库的使用及如何连接eclipse,参考     https://blog.csdn.net/lrici/article/de ...

  5. Yii1打印当前请求所有执行的SQL及耗时

    我们在熟悉新的项目了解业务的时候,可以有很多方式.看项目文档说明:和了解项目身边的人沟通:通过自己度代码调试,但是一步步调试打印语句或许有点慢,如果可以调出当前请求的所有语句,那么很快可以熟悉他的业务 ...

  6. JavaScript if 条件语句

    JavaScript if 条件语句 使用: if(条件){ }else if(条件){ }else if(条件){ }else{ } 示例: // 判断相等 if(1==1){ } // 判断不等 ...

  7. Python socket实现处理多个连接

       socket实现处理多个连接 实现处理多个连接 使用whlie循环实现多个客户端,排队请求服务端 循环监听端口发送信息(windos,Linux) 1.Linux 系统如果客户端断开连接,会循环 ...

  8. 继上篇后的Excel批量数据导入

    上篇Excel动态生成模板,此篇将借用此模板进行Excel数据的批量导入. 说明:由于数据库中部分数据储存的是编码或者Id,因此,这里就需要用到上篇中的全局数据,判断是否有数据,有数据直接使用,没有数 ...

  9. 原生JS实现简易转盘抽奖

    我爱撸码,撸码使我感到快乐. 大家好,我是Counter. 本章带大家来简单的了解下原生JS实现转盘抽奖. 因为主要涉及到JS,在这里HTML和CSS起到的功能就没有那么重要, 因此,没有过多的阐述H ...

  10. LeetCode in action

    (1) Linked List: 2-add-two-numbers,2.cpp 19-remove-nth-node-from-end-of-list,TBD 21-merge-two-sorted ...