问题
CASE 1 arm-linux-gcc -v hello.c ==> WORKS
CASE 2
arm-linux-gcc -v -L/home/peter/igep2015/09Buildroot/buildroot-2016.02-TRY5/output/staging/usr/lib hello.c ==> DOESN'T WORK
ERROR:ld.bfd: cannot find /usr/lib/libc_nonshared.a
ERROR:ld.bfd: cannot find /lib/ld-linux.so.3
CASE 3 arm-linux-gcc -v --sysroot=/home/peter/igep2015/09Buildroot/buildroot-2016.02-TRY5/output/host/usr/armeb-buildroot-linux-gnueabi/sysroot/ hello.c ==>WORKS but says it is ignoring sysroot because it cannot find /usr/include so is like case#1 Note that buildroot-staging symlinks to buildroot-sysroot
The respective libc libraries are in:
/usr/local/xtools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot/usr/lib/:/usr/local/xtools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot/lib/
/home/peter/igep2015/09Buildroot/buildroot-2016.02-TRY5/output/host/usr/armeb-buildroot-linux-gnueabi/sysroot/usr/lib:/home/peter/igep2015/09Buildroot/buildroot-2016.02-TRY5/output/host/usr/armeb-buildroot-linux-gnueabi/sysroot/lib/
/arm-linux and Buildroot libraries seem identical. The cross-tool was used to build Buildroot.
The question is: why does arm-linux-gcc fail when I link to Buildroot staging libaries. This question arose because auto-tools ./configure fails with a -L to Buildroot. But I need the -L to access libSDL2, libfreetype etc in Buildroot in order to cross-compile SDL2_ttf.
Note: I am using (crosstool-NG 1.21.0) 5.1.0.
回答1:
Just don't do any of the things you are doing. The Buildroot cross-compiler is configured to automatically search for libraries in $(STAGING_DIR)/usr/lib and headers in $(STAGING_DIR)/usr/include. None of the hacks you are describing are needed.
回答2:
This is a really strange issue. /lib/ works but /usr/lib does not work.
Specifically...
arm-linux-gcc -L/home/peter/igep2015/09Buildroot/buildroot-2016.02-TRY5/output/host/usr/armb-buildroot-linux-gnueabi/sysroot/lib hello.c
....works
but...
arm-linux-gcc -L/home/peter/igep2015/09Buildroot/buildroot-2016.02-TRY5/output/host/usr/armb-buildroot-linux-gnueabi/sysroot/usr/lib hello.c
....fails
SOLVED:
NOTE: To solve these linker problems use the command.
arm-linux-gcc -Wl,--verbose -L/home/peter/igep2015/09Buildroot/buildroot- 2016.02-TRY5/output/staging/usr/lib hello.c
The reason CASE 2
arm-linux-gcc -Wl,--verbose -L/home/peter/igep2015/09Buildroot/buildroot-2016.02-TRY5/output/staging/usr/lib hello.c
didn't work is that -L... is searched first and libc.so (containing linker script commands dependent on the gcc sysroot for finding libc_nonshared.a etc) was found in Buildroot before being properly found in gcc libraries.
The reason CASE 1 and CASE 3
arm-linux-gcc -Wl,--verbose -L/home/peter/igep2015/09Buildroot/buildroot-2016.02-TRY5/output/staging/lib hello.c AND
arm-linux-gcc -Wl,--verbose hello.c
both worked is that no lib containing linker script commands dependent on gcc sysroot were found. Thus the proper linker script commands libc.so were found in gcc libraries.
Read the 2nd answer in crosstools-ng can't find pthread.so
and you will see that the gcc linker script command GROUP behaves as follows:
GROUP looks in sysroot IF
-1- script is inside sysroot prefix AND
-2- sysroot prefix is configured AND
-3- filename starts with a /
Otherwise GROUP looks in current directory only.
To confirm the sysroot prefix being used....
arm-linux-gcc -print-sysroot
/usr/local/xtools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot
There are several presumed ways to solve CASE 2 problem
Solution #1
Remove libc.so from Buildroot. Then the linker will continue searching and correctly find libc.so in gcc sysroot.
rm /home/peter/igep2015/09Buildroot/buildroot-2016.02-TRY5/output/staging/usr/lib/libc.so
Solution #2
Change the gcc sysroot to be Buildroot as in CASE 3.
Solution #3
Change the linker script commands in Buildroot's libc.so as follows:
From:
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.3 ) )
To:
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( ../../lib/libc.so.6 libc_nonshared.a AS_NEEDED ( ../../lib/ld-linux.so.3 ) )
来源:https://stackoverflow.com/questions/36682302/cant-access-buildroot-staging-libraries-via-configure-when-cross-compiling-i