Reputation: 9369
My situation with g++
is the following. I build a shared library called libplugin.so
, which is loaded at run-time by an application. This libplugin.so
links to some other shared libraries, with the -no-as-needed
linker option, and to a static library.
Since libplugin.so
itself does not use any of the symbols in the listed libraries, -no-as-needed
is required to make the dynamic loader load all the required libraries - which are really referenced by the static library only - when the plugin is loaded at run-time. On my x86
building machine, all the libraries listed as -no-as-needed
are installed in the system. So, the library is built fine there and the program is also ok.
Now I am trying to cross compile for ARM, but there are some problems, because the linker cannot find the libraries indicated as -no-as-needed
in the system when building libplugin.so
. The linked cannot find the libraries because they (deliberately) are not installed. I prefer not to install them.
So here is my question. As libplugin.so
does not directly reference the libraries passed to -no-as-needed
in any way, is there a way to "force" the linker to build libplugin.so
although the ARM libraries passed to -no-as-needed
do not exist in my x86 building system?
Below is an example:
arm-linux-gnueabihf-g++ -o libplugin.so module1.o module2.o -L./libstatic.a -Wl,--no-as-needed -lX11 -lXext -shared -s -fPIC
arm-linux-gnueabihf-ld: cannot find -lX11
Upvotes: 1
Views: 227
Reputation: 229088
Afaik you can't easily do that. But since your library doesn't use anything in the shared libraries you want to link to , you should be able to trick the linker by creating a dummy libX11 library and link to that:
arm-linux-gnueabihf-gcc -x c -shared -o libX11.so -Wl,-soname,libX11.so.6 /dev/null
This will create a rather empty libX11.so that you can link to. The important part is the soname of this library, which must match the soname of the real library - you can figure that out with e.g.
readelf -a /lib/libX11.so |grep soname
Upvotes: 1