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. 新装Windows Server 2008 r2无法连接有线网络

    新装的Windows Server 2008 r2没有网卡驱动,所以没有网络适配器. 首先,我在相同的型号电脑上查到这个主板的网卡驱动安装的是Intel(R) Ethernet Coinnection ...

  2. Feign 与 Hystrix

    Feign 与 Hystrix Feign是一个声明式的web服务客户端,它使得web服务调用非常的简单,当我们使用Feign时,Spring Cloud 整合了Ribbon和Eureka,从而为我们 ...

  3. lua语言中的假

    [1]测试及结论 (1)代码 local var_false = false local var_nil = nil if var_zero then print('var_zero : true') ...

  4. Java内存模型学习笔记

    Java内存模型(JMM):描述了java程序中各种变量(线程共享变量)的范根规则,以及在JVM中将变量存储到内存和从内存中读取出变量这样的底层细节.共享变量就是指一个线程中的变量在其他线程中也是可见 ...

  5. Java多态(注意事项)

    多态:相同类型的变量.调用同一方法时呈现出多种不同的行为特征,这就是多态. 1.引用变量在编译阶段只能调用其编译时类型所具有的方法,但运行时则执行它运行时类型所具有的方法,因此编写Java代码时.引用 ...

  6. JZ2440使用笔记之熟悉uboot和Linux的移植

    目录 一.点亮开发板:移植uboot.Linux内核.文件系统 1.1 配置上位机交叉编译环境 1.2 制作U-boot镜像文件 1.3 通过oflash.exe / openJTAG 烧写u-boo ...

  7. PXC添加新节点

    先拉数据,再启用节点,可以避免SST 拉数据 [root@pxc_node1_172.16.11.132 ~]# /usr/bin/innobackupex --defaults-file=/etc/ ...

  8. expect拷贝文件例子

    ----安装expectcd /tmp wget http://core.tcl.tk/tcl/zip/release/tcl.zipwget https://jaist.dl.sourceforge ...

  9. 剑指offer(33)丑数

    题目描述 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 题目分析 ...

  10. How to use “cat” command on “find” command's output?

    You can do this with find alone using the -exec action: find /location -size 1033c -exec cat {} + {} ...