OpenCV DisplayImage Example Errors
Hello OpenCV Community,
I have been an OpenCV python user for a while, but I just started to use OpenCV C++ recently. I installed and tested OpenCV 4.0 following the protocols on https://docs.opencv.org/4.0.0/d7/d9f/.... The program passed the tests after installation and it seems that the installation was successful.
[----------] Global test environment tear-down
[==========] 10797 tests from 228 test cases ran. (385130 ms total)
[ PASSED ] 10797 tests.
YOU HAVE 10 DISABLED TESTS
However, when I started to do the DisplayImage example on https://docs.opencv.org/4.0.0/db/df5/..., I got errors.
The "DisplayImage.cpp" is exactly the same to the one in the tutorial. My "CMakeLists.txt file" is this:
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( /usr/local/include/opencv4/ )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage /usr/local/lib )
The last few lines of the error is like this:
CMakeFiles/DisplayImage.dir/build.make:62: recipe for target 'CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o' failed
make[2]: *** [CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/DisplayImage.dir/all' failed
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Please provide some suggestions. Thank you very much.
Follow-up
I just output the stderror (~5000 lines) to file so I could see all the errors. In the first several lines of the error, it said:
[ 50%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o
In file included from /usr/local/include/opencv4/opencv2/core.hpp:52:0,
from /usr/local/include/opencv4/opencv2/opencv.hpp:52,
from /home/marine/Workspace/OpenCV_4_CPP/project/DisplayImage.cpp:2:
/usr/local/include/opencv4/opencv2/core/cvdef.h:654:4: error: #error "OpenCV 4.x+ requires enabled C++11 support"
# error "OpenCV 4.x+ requires enabled C++11 support"
^
In file included from /usr/include/c++/5/array:35:0,
from /usr/local/include/opencv4/opencv2/core/cvdef.h:659,
from /usr/local/include/opencv4/opencv2/core.hpp:52,
from /usr/local/include/opencv4/opencv2/opencv.hpp:52,
from /home/marine/Workspace/OpenCV_4_CPP/project/DisplayImage.cpp:2:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
It seems that I don't have C++ 11 support.
I added "set (CMAKE_CXX_STANDARD 11)" to "CMakeLists.txt file". It seems that this is helpful. However, I got the following erros.
``
marine@Marine-Dell:~/Workspace/OpenCV_4_CPP/project$ make
[ 50%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o
[100%] Linking CXX executable DisplayImage
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function
main':
DisplayImage.cpp:(.text+0xa1): undefined reference to cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
DisplayImage.cpp:(.text+0x13f): undefined reference to
cv::namedWindow ...
yea, it failed, but why ?
the real error must be a few lines up in the make output. can you take another look ?
Thank you for your response. I just made an update.
which
gcc --version
is it ?/usr/include/c++/5
<-- that looks quite outdatedmarine@Marine-Dell:~/Workspace/OpenCV_4_CPP/project$ gcc --version gcc (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Even if I passed all the tests after installation, will it still likely to be the gcc problem?
so, gcc5.5.0 does not support c++11 "out-of-the-box".
while compiling the opencv libs a
-std=c++11
flag was added automatically to the g++ cmdline (so that worked), we now have to find out, how to get that into your cmake scriptThank you for your quick response. I made an update to my post on how to add C++11 support to cmake. I got much fewer errors, but the error still exists.
imho, your opencv libs built all fine, and the only remaining problem is: "how to compile an example program".
what about a simple:
Thanks for the followup. There is no problem compile the program using the command you suggested. This means that my old gcc is fine. We have to figure out a way to do it using cmake, eventually probably. However, when I try to display an image using the executable file, I got errors.
marine@Marine-Dell:~/Workspace/OpenCV_4_CPP/project$ ./DisplayImage gta5.jpg ./DisplayImage: error while loading shared libraries: libopencv_core.so.4.0: cannot open shared object file: No such file or directory
I guess we have to tell the program where the lib is.