I am cross-compiling by binaries identically by CMake clauses like
add_executable(mybinary1 mybinary1.c util_temp.c)
target_link_libraries(mybinary1 m)
add_executable(mybinary2 mybinary2.c util_temp.c)
target_link_libraries(mybinary2 m)
Unfortunately, one of them fails when running on target platform:
/mybinary2: /lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.27' not found (required by ./mybinary2)
First binary runs well.
ldd shows
# ldd mybinary2
./mybinary2: /lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.27' not found (required by ./mybinary2)
linux-vdso.so.1 (0x7ed1d000)
/usr/lib/arm-linux-gnueabihf/libarmmem.so (0x76fa2000)
libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x76f27000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x76de6000)
/lib/ld-linux-armhf.so.3 (0x76fcc000)
# ldd mybinary1
linux-vdso.so.1 (0x7ee09000)
/usr/lib/arm-linux-gnueabihf/libarmmem.so (0x76ece000)
libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x76e53000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x76d12000)
/lib/ld-linux-armhf.so.3 (0x76efb000)
What does it mean and how to solve it? Can I compile against specific version of a library? Why does it refer GLIBS indirectly, via libm?
If I do
target_link_libraries(mybinary2 m -static)
it starts to work but binary becomes x20 larger.
I also tried
__asm__(".symver realpath,realpath@GLIBC_2.19");
int main(int argc, char *argv[])
in mybinary2.c with no effect.
target_link_libraries(mybinary2 m -static-libgcc -static-libstdc++)
in CMakeLists.txt with no effect.
target_link_libraries(mybinary2 m libc.so.6:2.19)
with error message
[build] /usr/lib/gcc-cross/arm-linux-gnueabihf/7/../../../../arm-linux-gnueabihf/bin/ld: cannot find -llibc.so.6:2.19
Is latter syntax correct? How to see, which version (and of what) is on my system?
I tried commands like
ld -llibc
but neither work.
On my target computer (it is Raspberry Pi with old version of OS):
# ldd --version
ldd (Debian GLIBC 2.19-18+deb8u10) 2.19
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
I don't know how to use cross ldd on source computer.
Based on what your target computer outputs via
ldd --versionand based on the error (which also explains why a static link works):You have a GLIBC version mismatch, i.e. you compile it using
GLIBC 2.27but on the target computer you haveGLIBC 2.19. You either need to crosscompile with a lower version than you are currently using or upgradeglibcon the target computer.EDIT: To clarify which errors and general info I mean:
1)
EDIT2: Did a quick search and assuming you are crosscompiling on debian you could use the following command to get available package versions:
Where
myPackagewill most likely belibc6-dev-armhf-crossfor your current needs.EDIT3: As Andrew Henle pointed out. The easiest solution is to directly compile your project on the target device (or a compilation environment that is identical to the one on the target). Consider the above only if the target device is limiting you in doing so.