In my program I need to load a shared library dynamically with dlopen()
. Both the program and the shared library are successfully cross-compiled for an ARM
architecture with the cross-compiler installed on my x86
. However, whenever the program tries to load the library at run time on ARM
, it fails giving this error:
undefined symbol: _dl_hwcap
I cannot find the culprit of this error.
Let me give details on how the shared library (libmyplugin.so
) is built on x86
first. I use the g++
cross-compiler as below:
/home/me/arm/gcc-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -march=armv7-a -mfloat-abi=hard -c -s -fPIC -o build/module1.o module1.cpp
/home/me/arm/gcc-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -march=armv7-a -mfloat-abi=hard -c -s -fPIC -o build/module2.o module2.cpp
/home/me/arm/gcc-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ -o dist/libmyplugin.so build/module1.o build/module2.o --sysroot /home/me/arm/sysroot/ -Wl,--no-as-needed -ldl -lX11 -lXext /home/me/arm/libstatic.a -shared -s -fPIC
Please pay attention to the following notes:
module1.cpp
andmodule2.cpp
are my source code files.libstatic.a
is a big archive of object.o
files implementing the stuff directly invoked/referenced bymodule1.cpp
andmodule2.cpp
. These object files have been compiled by others for the same ARM architecture as mine, with the same compiler flags, but using a slightly more updatedg++
compiler (v4.9
instead of myv4.8.3
). Unfortunately, I have no control on the building of these objects.--sysroot /home/me/arm/sysroot/
represents the remote filesystem of myARM OS
from which the localg++
cross-compiler can take the native libraries while linking.-Wl,--no-as-needed -ldl -lX11 -lXext
: these flags are required to force the dynamic loader to load theX11
libraries present on the system when my shared library is loaded by the program. In particular,--no-as-needed
is required because theX11
libraries are NOT directly referenced bymodule1.o
andmodule2.o
; on the contrary theX11
libraries are referenced by the static library only.
Note that all the above setup works on x86
. It's just that I don't understand what is the reason of the _dl_hwcap
symbol not resolved when the program tried to load the library on ARM
.
Do you have any idea how to investigate this issue?