Skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6

By | May 18, 2016

When cross-building a program (but this could also happen when building natively), it’s normal that we don’t have the environment variables and building flags set with the right paths that indicate where the toolchain and the sysroot are.

The wrong paths can lead to many types of building errors at different stages. This one happened to me recently:

arm-linux-gnueabi-gcc -L/opt/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabi/qt5/arm-buildroot-linux-gnueabi/sysroot/lib -L/opt/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabi/qt5/arm-buildroot-linux-gnueabi/sysroot/lib32 -L/opt/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabi/qt5/arm-buildroot-linux-gnueabi/sysroot/usr/lib -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lz myfile.o -o myfile
/opt/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabi/bin/../lib/gcc/arm-linux-gnueabi/4.9.3/../../../../arm-linux-gnueabi/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
collect2: error: ld returned 1 exit status

This linking error says that it is skipping an incompatible library that is searching in my host’s filesystem even though I explicitly indicated in the Makefile the paths to use in the environment variable LDFLAGS with the -L:

LDFLAGS = -L$(SYSROOT)/lib -L$(SYSROOT)/lib32 -L$(SYSROOT)/usr/lib -pthread -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lz 

The $SYSROOT environment variable was set correctly

To indicate the linker to use the right path you have to add the -Xlinker -rpath-link=/your/sysroot/path directives.

For adding the /lib and /usr/lib path that are in my sysroot, the previous setting of LDFLAGS becomes:

LDFLAGS = -L$(SYSROOT)/lib -L$(SYSROOT)/lib32 -L$(SYSROOT)/usr/lib -Xlinker -rpath-link=$(SYSROOT)/lib -Xlinker -rpath-link=$(SYSROOT)/usr/lib -pthread -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lz 

Now the linker does not complain anymore.

Leave a Reply

Your email address will not be published. Required fields are marked *