Ask Your Question
0

DisplayImage.cpp errors Using OpenCV with gcc and CMake

asked 2014-02-10 22:05:07 -0600

keowang gravatar image

Hi:

I've had issues in compiling DisplayImage.cpp, I've followed the tutorial here and to create a cmake file and generate executables, however, when I was compiling the problem with make it displays the following errors:

Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in DisplayImage.cpp.o
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in DisplayImage.cpp.o
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in DisplayImage.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [DisplayImage] Error 1
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [all] Error 2

I am using MacOS could anyone please help!

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-02-11 09:09:02 -0600

updated 2014-02-11 10:29:59 -0600

If you want to go with the cmake compilation follow the steps

Open a terminal and type:

a)

sudo gedit /etc/ld.so.conf.d/opencv.conf

or

sudo nano /etc/ld.so.conf.d/opencv.conf

b)in that paste :

usr/local/lib

c)save and close and then open a terminal and type:

pkg-config --cflags opencv

Result:

-I/usr/local/include/opencv -I/usr/local/include

And then tpye:

pkg-config --libs opencv

Result:

/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so

Then you can continue with the cmake tpye compilation

If error still exists add this line to CMakeLists.txt:

include_directories(${OpenCV_INCLUDE_DIR})

Otherwise there's another method of compilation:

One way of compiling:- 1)chmod +x FILENAME.cpp

2)

g++ -ggdb `pkg-config --cflags opencv` -o `basename FILENAME.cpp .cpp` FILENAME.cpp `pkg-config --libs opencv'

3)./FILENAME image.Ext

Hope this helps you :)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-10 22:05:07 -0600

Seen: 760 times

Last updated: Feb 11 '14