简体   繁体   English

编译基本的openCV程序时出错

[英]Error Compiling a basic openCV program

I installed openCV following the link mentioned below : https://help.ubuntu.com/community/OpenCV#aStep_1 我按照下面提到的链接安装了openCV: https : //help.ubuntu.com/community/OpenCV#aStep_1

The installation went smooth, Now when I compile my test program: using the following command : 现在,当我编译测试程序时,安装顺利进行:使用以下命令:

opencv openCVtest.cpp

it throws me the following error : 它引发了以下错误:

compiling openCVtest.cpp
g++: error: missing argument to ‘-l’
Output file => openCVtest

I looked up the script I am using to compile ( its given here ) and saw this particular line that will be used to compile my c++ code : 我抬起头,我使用的编译(其给出的剧本在这里 ),看到将用于编译我的C ++代码这一行:

g++ -ggdb `pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `pkg-config --libs opencv`;

I understand that "-l" is asking for some libraries, but I think I should not be passing anything other than my code to this script. 我知道“ -l”要求一些库,但是我认为除了我的代码之外,我不应该向该脚本传递任何内容。

PS here is the detail of what's executed in that line: PS这里是该行执行内容的详细信息:

hduser@ishan-Notebook-PC:~/Documents/OpenCv$ echo g++ -ggdb `pkg-config --cflags opencv` -o `basename opencvtest.cpp .cpp` opencvtest.cpp `pkg-config --libs opencv`

g++ -ggdb -I/usr/include/opencv -I/usr/include/opencv2 -o opencvtest opencvtest.cpp -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -l

Can you guys please help me figure out , what exactly am I doing wrong? 你们能帮我弄清楚,我到底在做什么错? Thanks ! 谢谢 !

UPDATE UPDATE

I found my opencv.pc file containing an extra "-l" I removed that flag and the above errors goes away : 我发现我的opencv.pc文件包含一个额外的“ -l”,我删除了该标志,以上错误消失了:

contents of opencv.pc file: opencv.pc文件的内容:

prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: opencv
Description: The opencv library
Version: 2.x.x
Cflags: -I${includedir}/opencv -I${includedir}/opencv2
Libs: -L${libdir} -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -l

Notice the extra "-l" in last line. 注意最后一行中的额外“ -l”

However , now I get the following error : 但是,现在出现以下错误:

openCVtest.cpp:1:39: fatal error: opencv2/highgui/highgui.hpp: No such file or directory
 #include "opencv2/highgui/highgui.hpp"

Seems that pkg-config is returning one extra -l at the end. 似乎pkg-config返回一个额外的-l You can try running the command without it by hand: 您可以尝试手动运行不带命令的命令:

g++ -ggdb -I/usr/include/opencv -I/usr/include/opencv2 -o opencvtest opencvtest.cpp -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy

Update: 更新:
For the second issue you are having, try to use the include paths without the opencv and opencv2 directories. 对于您遇到的第二个问题,请尝试使用包含opencvopencv2目录的包含路径。

So instead of this: 所以代替这个:

Cflags: -I${includedir}/opencv -I${includedir}/opencv2

Try this: 尝试这个:

Cflags: -I${includedir}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM