Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

g++ error: undefined reference to CommandLineParser

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

Can anyone help me to fix the error? What does -ggdb in the g++ command mean/do? I googled it but couldn't find it?

g++ error: undefined reference to CommandLineParser

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

Can anyone help me to fix the error? 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

g++ error: undefined reference to CommandLineParser

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? 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