Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross compilation: GCC ignores --sysroot

I'm trying to cross compile programs (currently avconv from libav) for a Nokia N9 phone using arm-linux-gnueabi-gcc from Linux Mint's 64-bit repository. The compiler's libc version is 2.15 and the phone has libc-2.10.1. They have an incompatibility in the math library, which gives me a segfault when I compile and run the avconv program from libav.

I'd need to compile and link against the older libc version, but I haven't managed to get the --sysroot option to work.

I made a small test program to avoid repeatedly configuring and compiling libav.

arm-linux-gnueabi-gcc --sysroot=/opt/CrossCompilation/NokiaN9/ -o output.sysroot hello.c
arm-linux-gnueabi-gcc -o output.nosysroot hello.c

Both commands create an identical output file. This is what hello.c looks like:

#include <stdio.h>
#include <math.h>

int main() {
    printf("Hello, World! Sin = %f\n", sin(0.6451));
}

The strangest part is that gcc completely ignores the --sysroot option. If I pass a nonexisting directory to sysroot, it still produces exactly the same output binary:

arm-linux-gnueabi-gcc --sysroot=/foo/bar -o output.foobar hello.c

It doesn't even complain about any errors. What's the problem?

like image 769
trololo Avatar asked Jul 11 '13 20:07

trololo


People also ask

What is Sysroot in GCC?

The –sysroot=<dir> option tells the compiler to prepend both header and library default directories with <dir>. This option affects the linker too since it also changes the search location for libraries. Then, the linker also has to support this option.

What is a Sysroot?

A sysroot is a scaled down version of your target's filesystem, it need only contain the libraries and headers which you will compile/link against. There are many ways to set up a sysroot, one is to copy the /usr and /lib directories from your target to somewhere on your host filesystem.

What is Sysroot for toolchain?

A sysroot is a directory which is considered to be the root directory for the purpose of locating headers and libraries. So for example if your build toolchain wants to find /usr/include/foo. h but you are cross-compiling and the appropriate foo. h is in /my/other/place/usr/include/foo.


1 Answers

since I wasted a few days messing with this before reading the comments, I'm going to post artless noise's comments as an answer:

"Run the compiler with arm-linux-gnueabi-gcc -v and look at the value of --with-sysroot; this is the directory the compiler was built with. If you have this directory present on your machine (maybe with a different compiler), then the --sysroot may not work[; and if you do not see --with-sysroot and instead see --with-libs, it] means your gcc is compiled without --sysroot support."

like image 150
jcomeau_ictx Avatar answered Sep 16 '22 21:09

jcomeau_ictx