gcccross-compilingldconfigurerootfs

Cross-compile software for a root file system


I would like to cross-compile software (libdrm-armada) for an armhf architecture. I have the root file system (~/rootfs) which contains the shared objects needed. This file system will be flashed onto eMMC and runs on a custom device. Libdrm-armada uses a configure script to generate the Makefile. When I run ./configure, it exits because it can't find the shared objects.

The --with-sysroot, LD_LIBRARY_PATH, LIBRARY_PATH, LIBS, PKG_CONFIG_LIBDIR, LIBDRM_LIBS parameters did not work.

./configure --build=x86_64-linux --host=arm-linux\
--prefix=~/test \
LDFLAGS=-L~/rootfs/usr/lib/arm-linux-gnueabihf\
CFLAGS=-I~/rootfs/usr/include \
CC=~/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc

The error I'm trying to solve shows up in config.log as:

...
configure:3269: /home/user/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -I/home/user/rootfs/usr/include  -L/home/user/rootfs/usr/lib/arm-linux-gnueabihf conftest.c  >&5
/home/user/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: cannot find /lib/arm-linux-gnueabihf/libc.so.6 
/home/user/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: cannot find /usr/lib/arm-linux-gnueabihf/libc_nonshared.a
/home/user/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/6.3.1/../../../../arm-linux-gnueabihf/bin/ld: cannot find /lib/arm-linux-gnueabihf/ld-linux-armhf.so.3
collect2: error: ld returned 1 exit status 
...

How should I compile the software correctly and install it into ~/rootfs?

EDIT (thanks Basile!):
You can investigate the source code by checking out the git repository.

git clone git://git.armlinux.org.uk/~rmk/libdrm-armada.git/;
cd libdrm-armada/;
mkdir m4; autoreconf -f -i;
./configure --build=[.. and so on ..]

Please note that the configure script generates the Makefile. If you run the ./configure command above, the error is stored in a file named config.log.


Solution

  • I've found the solution to my problem. I had to add the --sysroot flag to the LDFLAGS parameter.

    ./configure --build=x86_64-linux --host=arm-linux \
    --prefix=~/test \
    LDFLAGS='-L~/rootfs/usr/lib/arm-linux-gnueabihf --sysroot=~/rootfs' \
    CFLAGS=-I~/rootfs/usr/include \
    CC=~/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc

    Running make && make install results the output files being located in ~/test. The shared objects are of ARM type:

    ./lib/libdrm_armada.so.0.2.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=3b571c90a174e5a2cbc2da9496f98278ebb1a560, not stripped