Ask Your Question
1

g++ error: undefined reference to CommandLineParser

asked 2016-09-27 01:57:12 -0500

alienmon gravatar image

updated 2016-09-27 02:05:59 -0500

I am new to opencv, and learning from "opencv by example" book.

I finished the installation and wanted to run an example : opencv_version.cpp as suggested. In the book it said I need to run this:

g++ -ggdb 'pkg-config --cflags --libs opencv3' opencv_version.cpp -o /tmp/opencv_version && /tmp/opencv_version

but afterward I got error saying that pkg-config ... is not found. After googling, apparently the problem is , I should use ` insetad of '

SO then I ran

g++ -ggdb `pkg-config --cflags --libs opencv3` opencv_version.cpp -o /tmp/opencv_version && /tmp/opencv_version

Yes It started compiling , but I got the following error:

/tmp/ccLwWorD.o: In function `main':
/home/osboxes/opencv-3.0.0/samples/cpp/opencv_version.cpp:12: undefined reference to `cv::CommandLineParser::CommandLineParser(int, char const* const*, cv::String const&)'
/home/osboxes/opencv-3.0.0/samples/cpp/opencv_version.cpp:14: undefined reference to `cv::CommandLineParser::has(cv::String const&) const'
AND SO ON

which in short is undefined reference to commandlineparser.

Here is some snapshot of the source code:

#include <opencv2/core/utility.hpp>
//some code here
cv::CommandLineParser parser(argc, argv, keys); //line 12
  1. Can anyone help me to fix the error?
  2. What does 'pkg-config --cflags --libs opencv3' do? what's its role?
  3. (ANSWERED, see edit)What does -ggdb in the g++ command mean/do? I googled it but couldn't find it?

----------EDIT

I found out the -ggdb part already :

Options starting with -g, -f, -m, -O, -W, or --param are automatically passed on to the various sub-processes invoked by g++.

So It meant to used gdb: which is a debugger

edit retag flag offensive close merge delete

Comments

1

please try to use opencv3.1.

berak gravatar imageberak ( 2016-09-27 02:12:59 -0500 )edit

Hi @berak I now try opencv3.1 and followed the tutorials using gcc but another error appear. I posted a new question here .

Appreciate if you can help :)

alienmon gravatar imagealienmon ( 2016-09-29 01:10:31 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-12-07 12:55:05 -0500

ccbrucer gravatar image

I had the same problem when reading "opencv by example" book. I tried many different things, and finally figured out that it was because of a linker issue, as described here: see here

Basically, you just need to change the command to

g++ -ggdb opencv_version.cpp `pkg-config --cflags --libs opencv3` -o /tmp/opencv_version && /tmp/opencv_version

Then it will work!!!

By the way, I also added the library path "/full/path/to/opencv-3.0.0/build/lib" to LD_LIBRARY_PATH in ~/.profile. Otherwise, there is an error about shared library.

edit flag offensive delete link more

Comments

This works well! Thanks!

weyoui gravatar imageweyoui ( 2018-11-18 20:27:27 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-09-27 01:57:12 -0500

Seen: 1,700 times

Last updated: Dec 07 '16