Cross-compiling error while using OpenCV in sample_camera application

Hi @VickNV ,

I tried with different configuration in CMakeLists.txt but it didn’t work.

Attaching the camera CMakeLists file.
CMakeLists.txt (1.8 KB)

Also, here is my code in main.cpp where the parameters to the Mat are (int, int, int, uint8_t * )
but the error is showing as undefined reference to `cv::Mat::Mat(int, int, int, void*, unsigned long)’

cv::Mat matImage = cv::Mat(imgCPU->prop.width, imgCPU->prop.height, CV_8UC3, imgCPU->data[0]);

I don’t have much experience with CMake. Any help would be highly appreciated.

Dear @VickNV ,

I’ve resolved the previous undefined reference errors by appropriately changing the CMakeLists.txt file of camera application.

StackOverflow: c++ - make error: undefined reference to cpp_redis::client::set(..) and cv::Mat::~Mat() - Stack Overflow

Attached here for future reference:
CMakeLists.txt (1.7 KB)

Now I’m facing the below error during make:
Error stack trace:

/usr/local/lib/libopencv_video.so.4.6.0: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status

Please help me resolve this error.

Good to hear that you solved the previous issue.

You may check if the library loaded by loader is in the right format as your executable.

I’m having different versions of libopencv_video.
Is the correct library being loaded for cross-compilation.

locate libopencv_video
/opt/opencv/release/lib/libopencv_video.so
/opt/opencv/release/lib/libopencv_video.so.4.6.0
/opt/opencv/release/lib/libopencv_video.so.406
/usr/lib/x86_64-linux-gnu/libopencv_video.a
/usr/lib/x86_64-linux-gnu/libopencv_video.so
/usr/lib/x86_64-linux-gnu/libopencv_video.so.3.2
/usr/lib/x86_64-linux-gnu/libopencv_video.so.3.2.0
/usr/local/lib/libopencv_video.so
/usr/local/lib/libopencv_video.so.4.6.0
/usr/local/lib/libopencv_video.so.406

Shall I use 3.2 version?

If it’s for cross-compilation, I think it should load ARM aarch64 libraries. You may use “file” command to check it.

Could you please specify which ARM aarch64 OpenCV version to install in my host-pc for cross-compilation along with the steps if possible.

Maybe you should refer to OpenCV: Cross compilation for ARM based Linux systems, or check OpenCV forums or communities.

Hi @VickNV,

Here are the OpenCV cross-compile steps I followed.

lidar@nvidia-drive:~/opencv_aarch64/opencv/platforms/linux/build_hardfp$ cmake -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..
-- The CXX compiler identification is GNU 7.5.0
-- The C compiler identification is GNU 7.5.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
.............
...........
............
-- 
-- General configuration for OpenCV 4.6.0-pre =====================================
--   Version control:               4.5.5-440-g9da9e8244b-dirty
-- 
--   Platform:
--     Timestamp:                   2022-06-02T06:08:36Z
--     Host:                        Linux 5.4.0-113-generic x86_64
--     Target:                      Linux 1 arm
--     CMake:                       3.17.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
-- 
--   CPU/HW features:
--     Baseline:
--       requested:                 DETECT
--       disabled:                  VFPV3 NEON
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 7.5.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
--     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          dl m pthread rt
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching ts video videoio
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 java python2 python3
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI:                           NONE
--     GTK+:                        NO
-- 
--   Media I/O: 
--     ZLib:                        zlib (ver 1.2.12)
--     JPEG:                        libjpeg-turbo (ver 2.1.2-62)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.2.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/lidar/opencv_aarch64/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python (for build):            /usr/bin/python2.7
-- 
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp
lidar@nvidia-drive:~/opencv_aarch64/opencv/platforms/linux/build_hardfp$ sudo make -j32
[sudo] password for lidar: 
Scanning dependencies of target opencv_highgui_plugins
Scanning dependencies of target quirc
Scanning dependencies of target libopenjp2
Scanning dependencies of target zlib
Scanning dependencies of target ittnotify
Scanning dependencies of target libprotobuf
Scanning dependencies of target opencv_videoio_plugins
Scanning dependencies of target ade
Scanning dependencies of target libjpeg-turbo
Scanning dependencies of target libwebp
[  0%] Built target opencv_highgui_plugins
[  0%] Building C object 3rdparty/quirc/CMakeFiles/quirc.dir/src/quirc.c.o
[  0%] Building C object 3rdparty/quirc/CMakeFiles/quirc.dir/src/decode.c.o
[  0%] Building C object 3rdparty/quirc/CMakeFiles/quirc.dir/src/version_db.c.o
[  0%] Built target opencv_videoio_plugins
[  0%] Building C object 3rdparty/ittnotify/CMakeFiles/ittnotify.dir/src/ittnotify/jitprofiling.c.o
[  0%] Building C object 3rdparty/ittnotify/CMakeFiles/ittnotify.dir/src/ittnotify/ittnotify_static.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/compress.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/adler32.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/crc32.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzclose.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/deflate.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzread.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzlib.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/gzwrite.c.o
[  1%] Building CXX object CMakeFiles/ade.dir/3rdparty/ade/ade-0.1.1f/sources/ade/source/edge.cpp.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/infback.c.o
[  1%] Building CXX object CMakeFiles/ade.dir/3rdparty/ade/ade-0.1.1f/sources/ade/source/assert.cpp.o
[  1%] Building CXX object CMakeFiles/ade.dir/3rdparty/ade/ade-0.1.1f/sources/ade/source/alloc.cpp.o
[  1%] Building CXX object CMakeFiles/ade.dir/3rdparty/ade/ade-0.1.1f/sources/ade/source/execution_engine.cpp.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/inftrees.c.o
[  1%] Building CXX object CMakeFiles/ade.dir/3rdparty/ade/ade-0.1.1f/sources/ade/source/graph.cpp.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/inflate.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/trees.c.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/inffast.c.o
[  1%] Building CXX object CMakeFiles/ade.dir/3rdparty/ade/ade-0.1.1f/sources/ade/source/memory_descriptor.cpp.o
[  1%] Building C object 3rdparty/zlib/CMakeFiles/zlib.dir/zutil.c.o
.............................
....................................
........................................
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/common/gapi_video_tests.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/common/gapi_render_tests.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_core_tests_fluid.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/common/gapi_operators_tests.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_imgproc_tests_cpu.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_ocv_stateful_kernel_tests.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_imgproc_tests_fluid.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_operators_tests_cpu.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_operators_tests_fluid.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_stereo_tests_cpu.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/executor/gtbbexecutor_internal_tests.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/cpu/gapi_video_tests_cpu.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_array_tests.cpp.o
[ 95%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_async_test.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_basic_hetero_tests.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_compile_args_tests.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_desc_tests.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_fluid_parallel_rois_test.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_fluid_resize_test.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_fluid_roi_test.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_fluid_test.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_fluid_test_kernels.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_frame_tests.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_gcompiled_tests.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_gcomputation_tests.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_gpu_test.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_graph_meta_tests.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_kernel_tests.cpp.o
[ 96%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_opaque_tests.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_plaidml_pipelines.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_planar_test.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_sample_pipelines.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_scalar_tests.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_smoke_test.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_transform_tests.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_typed_tests.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gapi_util_tests.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gpu/gapi_core_tests_gpu.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gpu/gapi_imgproc_tests_gpu.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/gpu/gapi_operators_tests_gpu.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/infer/gapi_infer_ie_test.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/infer/gapi_infer_onnx_test.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/infer/gapi_infer_tests.cpp.o
[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_backend_tests.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_dynamic_graph.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_executor_tests.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_garg_test.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_gmetaarg_test.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_gmodel_builder_test.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_island_fusion_tests.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_pattern_matching_test.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_island_tests.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_perform_substitution_test.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_proto_tests.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_recompilation_test.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_vectorref_test.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_transactions_test.cpp.o
[ 98%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/oak/gapi_tests_oak.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/own/conc_queue_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/own/gapi_types_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/own/last_written_value_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/own/mat_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/own/scalar_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/render/ftp_render_test.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/render/gapi_render_tests_ocv.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/rmat/rmat_integration_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/rmat/rmat_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/rmat/rmat_view_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/s11n/gapi_s11n_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/s11n/gapi_sample_pipelines_s11n.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/streaming/gapi_gstreamer_pipeline_facade_int_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/streaming/gapi_gstreamersource_tests.cpp.o
[ 99%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/streaming/gapi_streaming_sync_tests.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/streaming/gapi_streaming_tests.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/streaming/gapi_streaming_utils_test.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/streaming/gapi_streaming_vpl_core_test.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/streaming/gapi_streaming_vpl_data_provider.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/streaming/gapi_streaming_vpl_device_selector.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/streaming/gapi_streaming_vpp_preproc_test.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/test_main.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/util/any_tests.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/util/optional_tests.cpp.o
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/util/variant_tests.cpp.o
[100%] Linking CXX executable ../../bin/opencv_perf_gapi
[100%] Built target opencv_perf_gapi
[100%] Linking CXX executable ../../bin/opencv_test_gapi
[100%] Built target opencv_test_gapi
lidar@nvidia-drive:~/opencv_aarch64/opencv/platforms/linux/build_hardfp$ 

After successful MAKE I included all cross-compiled specific libraries in CMakeLists.txt for CAMERA application as shown below:

target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBRARIES}
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_core.so.406"

After doing these steps I cross-compiled again but during MAKE I’m again facing same error:

/build_hardfp/lib/libopencv_core.so.406: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status

I’m unable to understand how to proceed forward.

Please assign a specific person who has previously cross-compiled OpenCV dependency in driveworks.

Have you checked its file type with “file” command?

lidar@nvidia-drive:~/Documents/Nvidia_Drive/buildCrossCompile$ file /home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_core.so.4.6.0
/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_core.so.4.6.0: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=31e88a4d997d84126dd6bc36cfd7e32906b8b1d8, not stripped

All of the libraries are of x86-64 version.

x86-64 version cannot be used for cross-compiling. That’s why I suggested you check if there is any information in OpenCV forums or communities.

Hi @VickNV , I’m able to resolve the library issue by following this guide - OpenCV: Cross compilation for ARM based Linux systems

lidar@nvidia-drive:~/opencv_aarch64/opencv/platforms/linux/build_hardfp$ cmake -DCMAKE_TOOLCHAIN_FILE=../aarch64-gnu.toolchain.cmake ../../..
.....
.....
lidar@nvidia-drive:~/opencv_aarch64/opencv/platforms/linux/build_hardfp$ make -j32
....
....
[ 99%] Built target opencv_perf_gapi
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/util/variant_tests.cpp.o
[100%] Linking CXX executable ../../bin/opencv_test_gapi
[100%] Built target opencv_test_gapi

lidar@nvidia-drive:~/opencv_aarch64/opencv/platforms/linux/build_hardfp$ file /home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_core.so.4.6.0
/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_core.so.4.6.0: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=06e3d678873383f824e0145835eb538a624493a5, not stripped

Now I tried rebuilding but there are still few undefined reference errors:

/home/lidar/Documents/Nvidia_Drive/DRIVE_OS_5.2.0_SDK_Linux_OS_DRIVE_AGX_XAVIER/DRIVEOS/drive-t186ref-linux/targetfs/lib/aarch64-linux-gnu/libc-2.27.so: undefined reference to `_dl_exception_create@GLIBC_PRIVATE'
/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_dnn.so.4.6.0: undefined reference to `powf@GLIBC_2.27'
/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_dnn.so.4.6.0: undefined reference to `expf@GLIBC_2.27'
/home/lidar/Documents/Nvidia_Drive/DRIVE_OS_5.2.0_SDK_Linux_OS_DRIVE_AGX_XAVIER/DRIVEOS/drive-t186ref-linux/targetfs/lib/aarch64-linux-gnu/libc-2.27.so: undefined reference to `__tunable_get_val@GLIBC_PRIVATE'
/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_video.so.4.6.0: undefined reference to `log2f@GLIBC_2.27'
/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_core.so.4.6.0: undefined reference to `logf@GLIBC_2.27'
collect2: error: ld returned 1 exit status

CMakeLists of Camera:

project(sample_camera C CXX)
find_library(TACOPIE_LIBRARY tacopie)
#-------------------------------------------------------------------------------
# Project files
#-------------------------------------------------------------------------------
set(PUBLIC_DOCS
    README.md
)

set(SOURCES
    main.cpp
)

set(LIBRARIES
    ${Driveworks_LIBRARIES}
    samples_framework
    lodepng-src
)

#-------------------------------------------------------------------------------
# Final target
#-------------------------------------------------------------------------------
link_directories("/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/")

add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBRARIES}
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_core.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_calib3d.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_dnn.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_features2d.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_flann.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_gapi.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_highgui.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_imgcodecs.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_imgproc.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_ml.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_objdetect.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_photo.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_stitching.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_video.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_videoio.so.4.6.0"
"/home/lidar/Documents/Nvidia_Drive/DRIVE_OS_5.2.0_SDK_Linux_OS_DRIVE_AGX_XAVIER/DRIVEOS/drive-t186ref-linux/targetfs/lib/aarch64-linux-gnu/libc-2.27.so"
${TACOPIE_LIBRARY}
)
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Samples")

# ------------------------------------------------------------------------------
# Install target
# ------------------------------------------------------------------------------
sdk_add_sample(${PROJECT_NAME})
sdk_add_sample_data(${PROJECT_NAME} "samples/sensors/camera/camera")

Please let me know what should I include in CMakeLists to resolve the undefined reference errors.

Also one more question, I have been using CPP_REDIS for sending camera frames in-memory to another process but again cross compilation issue is there so any other alternative to achieve this? Can ROS be a feasible option?

Inlcuding OpenCV in DriveWorks is still throwing the below linker errors.
Could please advice on how to resolve them:

/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_dnn.so.4.6.0: undefined reference to `powf@GLIBC_2.27'
/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_dnn.so.4.6.0: undefined reference to `expf@GLIBC_2.27'
/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_video.so.4.6.0: undefined reference to `log2f@GLIBC_2.27'
/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_core.so.4.6.0: undefined reference to `logf@GLIBC_2.27'

CMakeList

project(sample_camera C CXX)
#-------------------------------------------------------------------------------
# Project files
#-------------------------------------------------------------------------------
set(PUBLIC_DOCS
    README.md
)

set(SOURCES
    main.cpp
)

set(LIBRARIES
    ${Driveworks_LIBRARIES}
    samples_framework
    lodepng-src
)

#-------------------------------------------------------------------------------
# Final target
#-------------------------------------------------------------------------------
#link_directories("/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/")

add_executable(${PROJECT_NAME} ${SOURCES})

target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBRARIES}
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_core.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_calib3d.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_dnn.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_features2d.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_flann.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_gapi.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_highgui.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_imgcodecs.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_imgproc.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_ml.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_objdetect.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_photo.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_stitching.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_video.so.4.6.0"
"/home/lidar/opencv_aarch64/opencv/platforms/linux/build_hardfp/lib/libopencv_videoio.so.4.6.0"
)

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Samples")

# ------------------------------------------------------------------------------
# Install target
# ------------------------------------------------------------------------------
sdk_add_sample(${PROJECT_NAME})
sdk_add_sample_data(${PROJECT_NAME} "samples/sensors/camera/camera")

GLibc version:

lidar@nvidia-drive:~/Documents/Nvidia_Drive/buildCrossCompile$ ldd --version
ldd (Ubuntu GLIBC 2.27-3ubuntu1.5) 2.27
Copyright (C) 2018 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.
Written by Roland McGrath and Ulrich Drepper.
lidar@nvidia-drive:~/Documents/Nvidia_Drive/buildCrossCompile$ 

All shared libraries are having undefined reference with one/more the following:

  • `powf@GLIBC_2.27’
  • `expf@GLIBC_2.27’
  • `log2f@GLIBC_2.27’
  • `logf@GLIBC_2.27’

Please help in resolving this error so that OpenCV gets cross-compiled correctly with DriveWorks.

Please see if Meet "undefined reference to `log2f@GLIBC_2.27'" error when using the crosscompile toolchain helps. Thanks.

Hey @VickNV , this discussion Meet "undefined reference to `log2f@GLIBC_2.27'" error when using the crosscompile toolchain doesn’t talk about how to resolve my issue as they are pointing to symbolic links but here in my CMakeLists I have externally given absolute paths to the .so files.
I have never experienced such issues before. Please advice.

Maybe you need to ensure these OpenCV libraries are also compiled by glibc 2.27.

You may be able to solve that library error by adding an environment variable or adding them in .bashrc file

LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH

@a.sreekumar.515 , thanks for your kind help but in my case this fix didn’t work. I’m still getting the same error.

Dear @VickNV , Could you please provide any reference blog or similar?

I don’t have any reference blog. Please make sure you use the same cross-compiling toolchains (the one below) for both OpenCV and your application.

~/nvidia/nvidia_sdk/DRIVE_OS_5.2.0*/DRIVEOS/toolchains