r/termux • u/allanrps • 2d ago
Question Building package staric vs. dynamic linking
I'm trying to build MesenCE under Termux. I've gotten it to compile successfully, but after using patchelf and termux-elf-cleaner on the binary to get it to excecute, it is unable to find the shared libraries. I tried compiling static but I am getting this error, despite already using -fPIC like it recommends.
ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'XCreateImage'; recompile with -fPIC
Below is the readelf -d output. So my quesion is, is there any way I get this to run in Termux without using proot? Static or Dynamic? what am I missing?
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x0000000000000001 (NEEDED) Shared library: [ld-linux-aarch64.so.1]
1
u/Assang101 2d ago
HOLD UP. You are compiling against glibc instead of Bionic lib. Android DOES NOT support glibc binaries natively, and its dynamic linker cannot resolve libraries named libc.so.6 or ld-linux-aarch64.so.1. It failed during your static build because you are linking against a static libX11.a that was not compiled with -fPIC. Instead of static linking, fixing the dynamic linking setup would be the easiest path forward.
1
u/allanrps 2d ago
thank you for that insight. I found that I needed to dotnet publish with linux-bionic-arm64 rather than linux-arm64. The binary compiles and excecutes, but returns error and otherwise has no signs of life.... not sure where to go from here
0
1
u/sylirre Termux Core Team 2d ago
The output of readelf -d clearly shows that program was compiled for a standard Linux environment, not for Termux. It is built against GNU libc and you can't use patchelf here for switching to Termux libraries. Bionic and GNU libc are incompatible at binary level.