I have changed the Makefile and I think its is compiling it now.But there are various errors that came up,
abc@ubuntu:~/Desktop$ make
g++ test1.cpp -o test1
/tmp/cci8pxyb.o: In function `main':
test1.cpp:(.text+0xa9): undefined reference to `cv::imread(cv::String const&, int)'
test1.cpp:(.text+0x142): undefined reference to `cv::namedWindow(cv::String const&, int)'
test1.cpp:(.text+0x199): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
test1.cpp:(.text+0x1c1): undefined reference to `cv::waitKey(int)'
/tmp/cci8pxyb.o: In function `cv::String::String(char const*)':
test1.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cci8pxyb.o: In function `cv::String::~String()':
test1.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/cci8pxyb.o: In function `cv::Mat::~Mat()':
test1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cci8pxyb.o: In function `cv::Mat::release()':
test1.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
/tmp/cci8pxyb.o: In function `cv::Mat::operator=(cv::Mat&&)':
test1.cpp:(.text._ZN2cv3MataSEOS0_[_ZN2cv3MataSEOS0_]+0xd4): undefined reference to `cv::fastFree(void*)'
collect2: error: ld returned 1 exit status
<builtin>: recipe for targ
Hey @isaac thank for the reply,As specified by you I have added the -lopencv_imcodecs to the makefile
and recompiled the code.
and this is the result that i am getting.
abc@ubuntu:~/Desktop$ make
g++ test1.cpp -o test1
/tmp/ccPnIH4h.o: In function main': test1.cpp:(.text+0xa9): undefined reference to cv::imread(cv::String const&, int)’
test1.cpp:(.text+0x142): undefined reference to cv::namedWindow(cv::String const&, int)' test1.cpp:(.text+0x199): undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)’
test1.cpp:(.text+0x1c1): undefined reference to cv::waitKey(int)' /tmp/ccPnIH4h.o: In function cv::String::String(char const*)‘:
test1.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to cv::String::allocate(unsigned long)' /tmp/ccPnIH4h.o: In function cv::String::~String()’:
test1.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to cv::String::deallocate()' /tmp/ccPnIH4h.o: In function cv::Mat::~Mat()‘:
test1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to cv::fastFree(void*)' /tmp/ccPnIH4h.o: In function cv::Mat::release()’:
test1.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to cv::Mat::deallocate()' /tmp/ccPnIH4h.o: In function cv::Mat::operator=(cv::Mat&&)‘:
test1.cpp:(.text.ZN2cv3MataSEOS0[ZN2cv3MataSEOS0]+0xd4): undefined reference to cv::fastFree(void*)' collect2: error: ld returned 1 exit status : recipe for target 'test1' failed make: *** [test1] Error 1 abc@ubuntu:~/Desktop$ make g++ test1.cpp -o test1 /tmp/ccPnIH4h.o: In function main’:
test1.cpp:(.text+0xa9): undefined reference to cv::imread(cv::String const&, int)' test1.cpp:(.text+0x142): undefined reference to cv::namedWindow(cv::String const&, int)’
test1.cpp:(.text+0x199): undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)' test1.cpp:(.text+0x1c1): undefined reference to cv::waitKey(int)’
/tmp/ccPnIH4h.o: In function cv::String::String(char const*)': test1.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to cv::String::allocate(unsigned long)’
/tmp/ccPnIH4h.o: In function cv::String::~String()': test1.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to cv::String::deallocate()’
/tmp/ccPnIH4h.o: In function cv::Mat::~Mat()': test1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to cv::fastFree(void*)’
/tmp/ccPnIH4h.o: In function cv::Mat::release()': test1.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to cv::Mat::deallocate()’
/tmp/ccPnIH4h.o: In function cv::Mat::operator=(cv::Mat&&)': test1.cpp:(.text._ZN2cv3MataSEOS0_[_ZN2cv3MataSEOS0_]+0xd4): undefined reference to cv::fastFree(void*)’
collect2: error: ld returned 1 exit status
: recipe for target ‘test1’ failed
make: *** [test1] Error 1
Why does ${CC} get expanded to g++ when it should be something like
CC = ${SYSROOTS}/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstro$
(I assume your copy paste operation does not show the end of the line, but there should be some kind of long path and not just g++ which will call the native x86 compiler)
Additionally there should be the sideeffects of ‘${CFLAGS} ${INCLUDES} ${LIB_PATH} ${LIBS}’…
Are you sure that you have configured the environment variable to for cross-compilation by running source /usr/local/oecore-x86_64/environment-setup-... script? Have you built the SDK you are suing by bitbake <your-image-name> -c populate_sdk after adding opencv package to the configuration?
Linker still cannot find the OpenCV binaries. I suspect if the OpenCV libs are present in the SDK. Would you mind to run this command and post the output?
Also, you can use CMake instead of Makefile since as it makes writing build files and resolving dependencies much simpler. A CMakeLists.txt for your code would be:
cmake_minimum_required(VERSION 3.1)
project(myApp)
add_executable(myApp test1.cpp)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(myApp ${OpenCV_LIBS})
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
The output is truncated. Write the output to a file by appending > log.txt to the command and attach the generated file in your response, (or use services like pastebin.com).
abc@ubuntu:~/Desktop$ nano CMakeLists.txt
abc@ubuntu:~/Desktop$ cmake
-- The C compiler identification is GNU 7.2.0
-- The CXX compiler identification is GNU 7.2.0
-- Check for working C compiler: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-gcc
-- Check for working C compiler: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-g++
-- Check for working CXX compiler: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr (found version "3.3.0")
-- OpenCV library status:
-- version: 3.3.0
-- libraries: opencv_calib3d;opencv_core;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_dpm;opencv_face;opencv_fuzzy;opencv_img_hash;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_reg;opencv_rgbd;opencv_saliency;opencv_stereo;opencv_structured_light;opencv_surface_matching;opencv_tracking;opencv_xfeatures2d;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
-- include path: /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include;/usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/opencv
-- Configuring done
-- Generating done
-- Build files have been written to: /home/abc/Desktop
Based on the output you posted, it seems you have the necessary libraries.
After running cmake, did you run make to build the project? It should do the job and build the binary unless something really weird is happening in your SDK.
As a side-tip, it is a good practice to build out of source tree to avoid polluting your source code with generated files for build.
For this purpose, create a directory like build and run cmake inside it. For instance, when you are in your source directory run the following:
abc@ubuntu:~/Desktop/sources/prog1$ make
Scanning dependencies of target myApp
[ 50%] Building CXX object CMakeFiles/myApp.dir/prog1.cpp.o
In file included from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/ext/string_conversions.h:41:0,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/bits/basic_string.h:6159,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/string:52,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/stdexcept:39,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/array:39,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/opencv2/core/cvdef.h:424,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/opencv2/core.hpp:52,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/opencv2/opencv.hpp:52,
from /home/abc/Desktop/sources/prog1/prog1.cpp:2:
/usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next
^~~~~~~~~~
compilation terminated.
CMakeFiles/myApp.dir/build.make:62: recipe for target 'CMakeFiles/myApp.dir/prog1.cpp.o' failed
make[2]: *** [CMakeFiles/myApp.dir/prog1.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/myApp.dir/all' failed
make[1]: *** [CMakeFiles/myApp.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
These are the errors that I am getting from Using Cmake ,I did find that in provious makefile I left the part " test1: test1.cpp" !
As Specified by you I have created the CMakeLists.txt file and copied your code in that. And Ran Cmake and Make after that.
The above Error are Generated as shown.
abc@ubuntu:/usr/local/oecore-x86_64$ ls
environment-setup-armv7at2hf-vfp-angstrom-linux-gnueabi
site-config-armv7at2hf-vfp-angstrom-linux-gnueabi
sysroots
version-armv7at2hf-vfp-angstrom-linux-gnueabi
abc@ubuntu:/usr/local/oecore-x86_64$ . environment-setup-armv7at2hf-vfp-angstrom-linux-gnueabi
abc@ubuntu:/usr/local/oecore-x86_64$ cd
abc@ubuntu:~$ cd Desktop
abc@ubuntu:~/Desktop$ cd sources
abc@ubuntu:~/Desktop/sources$ cmake -DENABLE_PRECOMPILED_HEADERS=OFF
-- OpenCV library status:
-- version: 3.3.0
-- libraries: opencv_calib3d;opencv_core;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_dpm;opencv_face;opencv_fuzzy;opencv_img_hash;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_reg;opencv_rgbd;opencv_saliency;opencv_stereo;opencv_structured_light;opencv_surface_matching;opencv_tracking;opencv_xfeatures2d;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
-- include path: /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include;/usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/opencv
-- Configuring done
-- Generating done
-- Build files have been written to: /home/abc/Desktop/sources
abc@ubuntu:~/Desktop/sources$ make
Scanning dependencies of target ImageProcessing
[ 50%] Building CXX object CMakeFiles/ImageProcessing.dir/one.cpp.o
In file included from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/ext/string_conversions.h:41:0,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/bits/basic_string.h:6159,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/string:52,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/stdexcept:39,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/array:39,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/opencv2/core/cvdef.h:424,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/opencv2/core.hpp:52,
from /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/opencv2/objdetect.hpp:47,
from /home/abc/Desktop/sources/one.cpp:1:
/usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/include/c++/7.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
CMakeFiles/ImageProcessing.dir/build.make:62: recipe for target 'CMakeFiles/ImageProcessing.dir/one.cpp.o' failed
make[2]: *** [CMakeFiles/ImageProcessing.dir/one.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/ImageProcessing.dir/all' failed
make[1]: *** [CMakeFiles/ImageProcessing.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
abc@ubuntu:~/Desktop/sources$
@max.tx@isaac I have Changed the Cmake According to the compilation error that I am receiving regarding the stdlib.h
Following is the errors that are received after that.
Read through here.
CMake is essentially a tool for generating build files (e.g. Makefile) automatically. It doesn’t do any magics. So you should be able to build the sources with a Makefile too. It is just easier to maintain and update a Cmake and it is more portable.
Did fixing the Makefile as you mentioned earlier made any difference?
There seems to be some issues with OpenCV in yocto. My colleagues also had some issues to get it working.
As for Cmake error:
Make sure you have cleaned up the working directory by deleting any CMakeCache, CMakeFiles, cmake_install, etc. There is no clean command for cmake and you have to do it manually. After than, run cmake with -DENABLE_PRECOMPILED_HEADERS=OFF switch again.
You probably should already have cmake support in your SDK, but just for being sure check this link: Yocto SDK with cmake toolchain file - Stack Overflow. You can verify whether this variable is set by running bitbake -e <your-image-name>.
One last resort is to use Makefile and specify the libraries by absolute path (e.g. /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-angstrom-linux-gnueabi/usr/lib/libopencv_highgui.so.3.3.0) and see how this works. This can could help to make sure the linker can find the libraries.