OpenCV - Library integration error
Hi,
As part of my project have a requirement of using OpenCV library on PLCnext.
I Compiled and built the files for OpenCV as outlined in the blog.
The include and the libs were generated and stored in /opt/pxc/install/include and /opt/pxc/install/lib respectively
But when did the build in eclipse, the FindOpenCV.cmake was not able to find the OpenCV_INCLUDE_DIR and the OpenCV_LIBRARY.
Then I manually copied the include files to /usr/local/include directory, post which the Find was a success as in the logs below. However, eventually the build is failing with the include file #include "opencv2/core.hpp” not found error.
In the logs below, It shows that the location of the OpenCV_INCLUDE_DIR is taken as /usr/local/include as default. Not sure why this is happening, even though my include and the library files were installed under /opt/pxc/install directory
/bin/sh -c "/home/umesh/plcncli/plcncli" generate code -p"/home/umesh/eclipse-workspace/OpenCVProject" --sources "src"
Successfully generated all files with the 'code' generator for /home/umesh/eclipse-workspace/OpenCVProject.
/bin/sh -c "/home/umesh/plcncli/plcncli" generate config -p"/home/umesh/eclipse-workspace/OpenCVProject" --sources "src"
Successfully generated all files with the 'config' generator for /home/umesh/eclipse-workspace/OpenCVProject.
/bin/sh -c "/home/umesh/plcncli/plcncli" build -p"/home/umesh/eclipse-workspace/OpenCVProject" -b Release -tAXCF2152,19.6.3.22423
Requested build for targets AXCF2152,19.6.3.22423
Starting build for target AXCF2152,19.6.3.22423
Checking if CMake needs to be reconfigured...
[cmake]: -- Setting ARP_TOOLCHAIN_NATIVE_SYSROOT='/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux'
[cmake]: -- Setting ARP_TOOLCHAIN_TARGET_SYSROOT='/opt/pxc/sdk/AXCF2152/2019.6/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi'
[cmake]: -- The C compiler identification is GNU 8.2.0
[cmake]: -- The CXX compiler identification is GNU 8.2.0
[cmake]: -- Check for working C compiler: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-gcc
[cmake]: -- Check for working C compiler: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-gcc -- works
[cmake]: -- Detecting C compiler ABI info
[cmake]: -- Detecting C compiler ABI info - done
[cmake]: -- Detecting C compile features
[cmake]: -- Detecting C compile features - done
[cmake]: -- Check for working CXX compiler: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-g++
[cmake]: -- Check for working CXX compiler: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-g++ -- works
[cmake]: -- Detecting CXX compiler ABI info
[cmake]: -- Detecting CXX compiler ABI info - done
[cmake]: -- Detecting CXX compile features
[cmake]: -- Detecting CXX compile features - done
[cmake]: THE CMAKE_CURRENT_SOURCE_DIR: /home/umesh/eclipse-workspace/OpenCVProject
[cmake]: PROJECT_SOURCE_DIR: /home/umesh/eclipse-workspace/OpenCVProject
[cmake]: -- Boost version: 1.63.0
[cmake]: -- Found the following Boost libraries:
[cmake]: -- regex
[cmake]: -- Found ArpProgramming: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi/usr/include/plcnext
[cmake]: -- Found OpenCV: /usr/local/include
[cmake]: OpenCV_LIBRARY: /usr/local/lib/libopencv_core.so
[cmake]: OpenCV_INCLUDE_DIRS : /usr/local/include
[cmake]: OpenCV_LIBS :
[cmake]: -- Configuring done
[cmake]: -- Generating done
[cmake]: -- Build files have been written to: /home/umesh/eclipse-workspace/OpenCVProject/intermediate/cmake/AXCF2152,19.6.3.22423/Release
[cmake]: Scanning dependencies of target OpenCVProject
[cmake]: [ 14%] Building CXX object CMakeFiles/OpenCVProject.dir/src/MyProgram.cpp.o
[cmake]: cc1plus: warning: include location "/usr/local/include" is unsafe for cross-compilation [-Wpoison-system-directories]
[cmake]: /home/umesh/eclipse-workspace/OpenCVProject/src/MyProgram.cpp:6:10: fatal error: opencv2/core.hpp: No such file or directory
[cmake]: #include "opencv2/core.hpp"
[cmake]: ^~~~~~~~~~~~~~~~~~
[cmake]: CMakeFiles/OpenCVProject.dir/build.make:127: recipe for target 'CMakeFiles/OpenCVProject.dir/src/MyProgram.cpp.o' failed
[cmake]: compilation terminated.
[cmake]: make[2]: *** [CMakeFiles/OpenCVProject.dir/src/MyProgram.cpp.o] Error 1
[cmake]: CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/OpenCVProject.dir/all' failed
[cmake]: make[1]: *** [CMakeFiles/OpenCVProject.dir/all] Error 2
[cmake]: make: *** [all] Error 2
[cmake]: Makefile:129: recipe for target 'all' failed
cmake process exited with error
Attached my CMakeLists.txt and FindOpenCV.cmake files
Please help.
Regards,
Umesh
Comments
Hello,
your FindOpenCV.cmake file is not found.
So Cmake defaults to the Operating System include directories.
You will have to add your "external " folder to the CMAKE_MODULE_PATH i think and place high priority on it.
But I am no expert on CMake there might be a better solution still..
Maybe even directly adding external include to "target_include_directories".
for Open CVs dependencies In the past i had to add something like this:
I checked with the logs inside FindOpenCV.cmake - I could see that a call has been made to the FindOpenCV.cmake and post that the OpenCV_INCLUDE_DIR is populated with the include directory path value.
I tried removing the CmakeCache.txt and re-build and everytime the below log appears,
Just one more thing , I found this in my CMakeError.log. Do you have any idea why this is happening?
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-gcc
Build flags: ;-march=armv7-a;-mthumb;-mfpu=neon;-mfloat-abi=hard;-mcpu=cortex-a9
Id flags:
The output was:
1
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find Scrt1.o: No such file or directory
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find crti.o: No such file or directory
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find crtbeginS.o: No such file or directory
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find -lgcc
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find -lgcc_s
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find -lc
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find -lgcc
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find -lgcc_s
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find crtendS.o: No such file or directory
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/8.2.0/real-ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
Regards,
Hi ,
I was able to have the FindOpenCV work, however got stuck at the compilation stage.
umesh@umesh-VirtualBox:~/eclipse-workspace/OpenCVProject/tools$ sudo ./build-OpenCVProject.sh -t "/opt/pxc/sdk/AXCF2152/2019.6" -a "2019.6.3 (19.6.3.22423 )" -n "AXCF2152"
[sudo] password for umesh:
Version:19.6.3.22423
CMAKE Configure
-- Setting ARP_TOOLCHAIN_NATIVE_SYSROOT='/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux'
-- Setting ARP_TOOLCHAIN_TARGET_SYSROOT='/opt/pxc/sdk/AXCF2152/2019.6/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi'
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-gcc
-- Check for working C compiler: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-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: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-g++
-- Check for working CXX compiler: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
THE CMAKE_CURRENT_SOURCE_DIR: /home/umesh/eclipse-workspace/OpenCVProject
CMAKE_MODULE_PATH:/opt/pxc/sdk/AXCF2152/2019.6/cmake/home/umesh/eclipse-workspace/OpenCVProject/cmake
-- Found Boost: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi/usr/include (found version "1.63.0") found components: regex
-- Found ArpProgramming: /opt/pxc/sdk/AXCF2152/2019.6/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi/usr/include/plcnext
Inside FindOpenCV.cmake
Finding OpenCV_INCLUDE_DIR: /usr/local/include
Finding OpenCV_LIBRARY:
Found OpenCV_LIBRARY: /usr/local/lib/libopencv_core.so
-- Found OpenCV: /usr/local/include
Found OpenCV_LIBRARY: /usr/local/lib/libopencv_core.so
Found OpenCV_LIBRARY: /usr/local/lib/libopencv_core.so
Found OpenCV_INCLUDE_DIR: /usr/local/include
Found OpenCV_LIBRARY: /usr/local/lib/libopencv_core.so
Found OpenCV_INCLUDE_DIR: /usr/local/include
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
BUILD_TESTING
USE_ARP_DEVICE
-- Build files have been written to: /home/umesh/eclipse-workspace/OpenCVProject/intermediate/cmake/AXCF2152_19.6.3.22423
[1/2] Building CXX object CMakeFiles/OpenCVProject.dir/src/MyProgram.cpp.o
FAILED: CMakeFiles/OpenCVProject.dir/src/MyProgram.cpp.o
/opt/pxc/sdk/AXCF2152/2019.6/sysroots/x86_64-pokysdk-linux/usr/bin/arm-pxc-linux-gnueabi/arm-pxc-linux-gnueabi-g++ --sysroot=/opt/pxc/sdk/AXCF2152/2019.6/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi -DARP_DEVICE_AXCF2152 -DOpenCVProject_EXPORTS -I../../code -I../../../src -I../../../depoly/include -I../../../deploy/include/opencv2 -I/opt/pxc/sdk/AXCF2152/2019.6/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi/usr/include/plcnext -isystem /usr/local/include -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -O3 -DNDEBUG -fPIC -fno-gnu-unique -MD -MT CMakeFiles/OpenCVProject.dir/src/MyProgram.cpp.o -MF CMakeFiles/OpenCVProject.dir/src/MyProgram.cpp.o.d -o CMakeFiles/OpenCVProject.dir/src/MyProgram.cpp.o -c ../../../src/MyProgram.cpp
cc1plus: warning: include location "/usr/local/include" is unsafe for cross-compilation [-Wpoison-system-directories]
In file included from ../../../src/MyProgram.cpp:12:
/usr/local/include/opencv4/opencv2/imgcodecs.hpp:46:10: fatal error: opencv2/core.hpp: No such file or directory
#include "opencv2/core.hpp"
^~~~~~~~~~~~~~~~
Not sure, why this error, even though the file is present at the location. Please help.
Regards,
Umesh