OPENCV cross-compilation linking error caused by libdl and librt - opencv

I'm trying to cross-compile OpenCV 4.5.1 for ARM targets. My host system is Linux 20.04 (based on Intel). I'm using CMake 3.16.3. Compilation without extra modules works fine. When I add them, I get a linking error towards the end:
[ 86%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/api/kernels_video.cpp.o
[ 86%] Linking CXX executable ../../../../bin/opencv_waldboost_detector
/home/alexis/Desktop/snapdragon/cross/lib/gcc/arm-linux-gnueabi/8.1.0/../../../../arm-linux-gnueabi/bin/ld: warning: libdl.so.2, needed by ../../../../lib/libopencv_core.so.4.5.1, not found (try using -rpath or -rpath-link)
/home/alexis/Desktop/snapdragon/cross/lib/gcc/arm-linux-gnueabi/8.1.0/../../../../arm-linux-gnueabi/bin/ld: warning: librt.so.1, needed by ../../../../lib/libopencv_core.so.4.5.1, not found (try using -rpath or -rpath-link)
../../../../lib/libopencv_core.so.4.5.1: undefined reference to `dladdr#GLIBC_2.4'
../../../../lib/libopencv_core.so.4.5.1: undefined reference to `dlclose#GLIBC_2.4'
../../../../lib/libopencv_core.so.4.5.1: undefined reference to `dlopen#GLIBC_2.4'
../../../../lib/libopencv_core.so.4.5.1: undefined reference to `dlsym#GLIBC_2.4'
../../../../lib/libopencv_core.so.4.5.1: undefined reference to `clock_gettime#GLIBC_2.4'
collect2: error: ld returned 1 exit status
I understand that the issue is because the two libraries libdl and librt cannot be found. The missing libraries are on a non standard path. I tried to set the LD_LIBRARY_PATH to the folder that contains the requested libraries but with no luck.
Not sure what else I could try. The error messages says to try using -rpath or -rpath-link, but I don't know how to do that.

Related

-lomp not found for openmp apple m1

I am currently trying to compile a cpp program with openmp. From what I have read online this is the command that I need to use for indeed using openmp on apple silicon:
g++ -Xpreprocessor -fopenmp -I/opt/homebrew/Cellar/libomp/14.0.6/include -L/usr/local/lib -lomp heat2D.cpp
I have installed everything required for openmp (libomp,llvm,etc...) but it gives me this error:
ld: library not found for -lomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
In addition if try to remove the lomp flag:
g++ -Xpreprocessor -fopenmp -I/opt/homebrew/Cellar/libomp/14.0.6/include heat2D.cpp
this is the error i get:
Undefined symbols for architecture arm64:
"_omp_set_num_threads", referenced from:
_main in heat2D-0b5aaa.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Since you mention that you installed GCC (and LLVM) via Homebrew, the problem is probably (as Jim Cownie suggested) that when you type "g++", you are running the default link to Apple's LLVM installation (which, alas, does not support OpenMP).
The problem is that Homebrew installs its versions of the compiler binary commands using versioned names -- e.g., "g++-12" if you installed the latest version of GCC. So you have to use those names if you want to run the Homebrew versions. (They are probably installed in /opt/homebrew/bin/ in your case, since you have an Apple Silicon Mac.)
(I haven't installed Homebrew's version of LLVM, but it's probably a similar situation for that as well, since you wouldn't want it to overwrite Apple's LLVM commands.)

Problems linking FFTW with gfortran (symbol(s) not found for architecture x86_64)

I am on macOS Catalina (10.15.5) and I have installed FFTW using brew install fftw. I also have GCC (version 10.2.0) installed which is symlinked to the commands I am using below.
I am able to compile and run a simple C++ program like so:
g++-10 test.cpp -L/usr/local/lib -I/usr/local/include -lfftw3 -lm
But, I had to modify the environment variable CPATH to make this work.
I am unable to get a simple Fortran FFTW example to work (I am using this one). The command I am using to compile is:
gfortran-10 test.f90 -L/usr/local/lib -I/usr/local/include -lfftw3 -lm
The error I get is as follows:
Undefined symbols for architecture x86_64:
"__gfortran_os_error_at", referenced from:
_MAIN__ in ccRvJaEQ.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
If I understand correctly, the linking step fails. Any inputs on how I might find the relevant paths that I may have to pass to the compiler would be very helpful. I searched for solutions and I wasn't able to find one. But, in case I missed something obvious, I apologise.
Thanks to msi_gerva's helpful hints through comments, I was able to solve the issue by downloading FFTW and compiling it to a custom directory following the installation directions.
Now, the linking doesn't fail if I pass the new locations of the libraries to gfortran like so:
gfortran-10 test.f90 -L/new/path/to/lib -I/new/path/to/include -lfftw3 -lm
Since /usr/local/ is the default installation path, it's possible that there is a mixing up of the FFTW library files from previous installations.

Linking globals named 'fbad_Cocos2DGetGLViewController': symbol multiply defined

"ld: Linking globals named 'fbad_Cocos2DGetGLViewController': symbol
multiply defined! for architecture arm64 clang: error: linker command
failed with exit code 1 (use -v to see invocation)"
I'm getting this error in XCode build project have two SDKs "GoogleAdMob SDK Unity" and "FacebookAudienceNetwork" Unity.
Deleting -ObjC flag from other linker flags won’t work for me.
Is there anybody can help me fix that issue?
Single SDK build either its GoogleAdMOb Unity or FacebookAudienceNetwork Unity don't have any issue.
Adding both generate this error:
""ld: Linking globals named 'fbad_Cocos2DGetGLViewController': symbol
multiply defined! for architecture arm64"

make linking static libc not dynamic

I am trying to build an open source library (openCV in this case) from source using cmake and make. However, I run into a linking error
Linking CXX shared library ../../lib/libopencv_videoio.so
/usr/bin/ld: /usr/local/lib/libc.a(lib_a-mallocr.o): relocation R_X86_64_32S against `__malloc_av_' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libc.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_videoio.so.3.0.0] Error 1
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [all] Error 2
From what I gather, this means make is using the static version of glibc libc.a instead of the dynamic lib.so.6. I'm assuming I need to change a path somewhere in cmake but I'm unsure of where to look. Any help is appreciated.
edit: I'm doing this on a 64 bit linux mint machine

OpenSSL with FIPS cross compiling for iOS armv7

I cross compiled the FIPS for armv7 using the instructions from
http://opensslfoundation.com/testing/validation-2.0/platforms/ios/
I am having difficulties cross compiling openssl dependency on fips.
I am getting following error in terminal.
/usr/local/ssl/fips-2.0/bin/fipsld: line 185: ./openssl: Bad CPU type in executable
make[2]: *** [link_app.] Error 1
make[1]: *** [openssl] Error 2
make: *** [build_apps] Error 1
This is because the openssl executable under the "/apps" folder is of architecture armv7.
Since I am cross compiling openssl, I need only the libssl and libcrypto with architecture armv7, other intermediate executables should build with i386 architecture.
Any help with setting up the environment variables is appreciated.
The OpenSSL FIPS User Guide 2.0 has a comprehensive example of building the FIPS Object Module and FIPS Capable Library. It also offers a sample iOS program to test your build against. See Appendix E on p. 122.
From the looks of it (due to link_app error), you did not set your environment properly with setenv-ios-11.sh. That caused your build attempt to build the executables (which should not be built in this configuration).

Resources