来自终端的示例程序无法运行 [英] Sample Program From Terminal Could Not Run

查看:70
本文介绍了来自终端的示例程序无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ubuntu 中的 opencv 新手.我已经按照 here 中的教程来设置 opencv在Linux中.但是,我未能使 示例程序 运行.在我输入以下内容后,

I'm new to opencv in ubuntu. I've follow the tutorial from here for setting up the opencv in linux. However, I have failed to make the sample program runs. After I type the following,

$ g++ DisplayImage.cpp

出现这些错误,

/tmp/cc3GTOtQ.o: In function `main':
DisplayImage.cpp:(.text+0x53): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
DisplayImage.cpp:(.text+0xe5): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
DisplayImage.cpp:(.text+0x113): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
DisplayImage.cpp:(.text+0x147): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
DisplayImage.cpp:(.text+0x169): undefined reference to `cv::waitKey(int)'
/tmp/cc3GTOtQ.o: In function `cv::Mat::~Mat()':
DisplayImage.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cc3GTOtQ.o: In function `cv::Mat::operator=(cv::Mat const&)':
DisplayImage.cpp:(.text._ZN2cv3MataSERKS0_[cv::Mat::operator=(cv::Mat const&)]+0x111): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/cc3GTOtQ.o: In function `cv::Mat::release()':
DisplayImage.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status

推荐答案

这是使用 OpenCV 库的完整命令行构建 C++ 程序.

Here is the full command line build C++ program with OpenCV Libraries.

g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binaryName  main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy

如果您在不同的位置安装了 OpenCV,您应该将 'include' 和 lib 'directory' 的路径更改为适当的位置.

If you installed OpenCV in different location, you should change the path of 'include' and lib 'directory' to appropriate location.

-

不是每次只在项目目录中创建文件 build.sh 时都运行此命令,而是通过运行 chmod 777 build.sh 将其权限更改为可执行文件,然后构建项目只需运行此文件.

Instead of running this command every time just create a file build.sh in your project directory, change it's permission to executable by running chmod 777 build.sh and for building the project just run this file.

这篇关于来自终端的示例程序无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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