Nsight Eclipse: Link Errors when cross compiling opencv for Tegra (Xavier)

Hey,

I installed CUDA using the SDK (4.2) and successfully flushed the Xavier Image.
I successfully build (cross-compiled) images on my x86-64 computer (ubuntu 18.04) and successfully load/run/debug the application on my Xavier.

At this point I added some “opencv” API’s to my application and got link errors (undefined reference)

Invoking: NVCC Linker
/usr/local/cuda-10.0/bin/nvcc --cudart static -L/home/ubuntu/opencv_3.3.1_aarch64 --relocatable-device-code=false -gencode arch=compute_61,code=compute_61 -gencode arch=compute_61,code=sm_61 -m64 -ccbin aarch64-linux-gnu-g++ -link -o  "Simple_opencv"  ./main.o   
./main.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x48): undefined reference to `cv::String::allocate(unsigned long)'
./main.o: In function `cv::Mat::~Mat()':
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x84): undefined reference to `cv::fastFree(void*)'
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x94): undefined reference to `cv::Mat::deallocate()'
./main.o: In function `main':
makefile:58: recipe for target 'Simple_opencv' failed
main.cpp:(.text.startup+0xac): undefined reference to `cv::imread(cv::String const&, int)'
main.cpp:(.text.startup+0x12c): undefined reference to `cv::fastFree(void*)'
main.cpp:(.text.startup+0x188): undefined reference to `cv::String::deallocate()'
main.cpp:(.text.startup+0x1d4): undefined reference to `cv::Canny(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, bool)'
main.cpp:(.text.startup+0x1f0): undefined reference to `cv::namedWindow(cv::String const&, int)'
main.cpp:(.text.startup+0x1f8): undefined reference to `cv::String::deallocate()'
main.cpp:(.text.startup+0x224): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
main.cpp:(.text.startup+0x22c): undefined reference to `cv::String::deallocate()'
main.cpp:(.text.startup+0x234): undefined reference to `cv::waitKey(int)'
main.cpp:(.text.startup+0x2c0): undefined reference to `cv::Mat::deallocate()'
main.cpp:(.text.startup+0x328): undefined reference to `cv::String::deallocate()'
main.cpp:(.text.startup+0x34c): undefined reference to `cv::String::deallocate()'
main.cpp:(.text.startup+0x35c): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
make: *** [Simple_opencv] Error 1

At this point I now I have 2 options:

  1. Get the suitable libraries (aarch 64)
    so I copied the following libraries from the Xavier into my ld path

    • opencv_core
    • opencv_highgui
    • opencv_imgproc
    • opencv_imgcodecs

    but now I get many other dependency errors…(copied only few… there are many!)

/home/ubuntu/opencv_3.3.1_aarch64/libopencv_imgcodecs.so: undefined reference to `png_set_filter@PNG16_0'
..
/home/ubuntu/opencv_3.3.1_aarch64/libopencv_imgcodecs.so: undefined reference to `png_get_IHDR@PNG16_0'
..
/home/ubuntu/opencv_3.3.1_aarch64/libopencv_highgui.so: undefined reference to `gtk_widget_queue_draw'
..
..
/home/ubuntu/opencv_3.3.1_aarch64/libopencv_core.so: undefined reference to `gzeof'

which leads me to solution #2:

  1. Dynamically link only (How???)
    Doing so will be very helpful… but I need help

If anyone here can assist me on this issue, I’ll be very grateful!
Thanks!

OK… meanwhile i found a good link.

https://devblogs.nvidia.com/cuda-jetson-nvidia-nsight-eclipse-edition/