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. git之摘抄

    vn中央集权, 统一服务器, 权限安全管理 git 分布式,代码仓库历史本地有,不受约束, 可以随意开分支.

  2. 设置vim支持gbk

    linux下的默认字符集是utf-8,但Windows下默认是GBK,如果我们在linux下打开Windows中的文件就很容乱码,可以通过下面的设置使vim支持GBK编码. 首先,确认你的系统中安装了 ...

  3. OpenStack-Neutron-VPNaaS-API

    1 命令 1.1 IKE策略 vpn-ikepolicy-create Create an IKEPolicy vpn-ikepolicy-delete Delete a given IKE Poli ...

  4. Zuul 网关路由

    Zuul 网关路由 路由是微服务架构中不可或缺的一部分,例如:/api/user映射到user服务,/api/shop映射到shop服务. Zuul是一个基于JVM的路由和服务端的负载均衡器.Zuul ...

  5. RNA-seq基本流程

    https://www.2cto.com/net/201801/714420.html

  6. Vue基础进阶 之 自定义指令

    自定义指令-----钩子函数 自定义指令 除了内置指令,Vue也允许用户自定义指令: 注册指令:通过全局API Vue.directive可以注册自定义指令: 自定义指令的钩子函数: bind: in ...

  7. Python while 循环

     while循环的使用 count = 0 while True: print("conunt:",count) conunt = conunt +1 注:while:作为循环命令 ...

  8. Linux 进程后台运行

    Linux 进程后台运行 1.进程在当前终端后台运行.(关闭终端后进程自动退出) sh test.sh & 注:运行进程后跟 “&” 2.进程长期后台运行不受终端关闭影响. nohup ...

  9. bitbucket迁移

    bitbucket 迁移 1.停止向旧仓库地址提交代码 [dev]2.导入代码至新仓库地址 [op]3.修改本地仓库地址 第一种方式:git remote set-url origin [url] ; ...

  10. 最短路径之Bellman-Ford——解决负权边

    Bellman-Ford算法非常简单,核心代码四行,可以完美的解决带有负权边的图. for(k=1;k<=n-1;k++) //外循环循环n-1次,n为顶点个数 for(i=1;i<=m; ...