Cross compilation: GCC ignores --sysroot
Asked Answered
S

2

20

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?

Skyros answered 11/7, 2013 at 20:47 Comment(4)
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. What is the gcc version?Father
There is no "--with-sysroot" defined. gcc is version 4.6.3Skyros
But instead 'grep /usr/arm' finds "--with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.6.3", "--includedir=/usr/arm-linux-gnueabi/include", "--with-headers=/usr/arm-linux-gnueabi/include", and "--with-libs=/usr/arm-linux-gnueabi/lib".Skyros
--with-libs means your gcc is compiled without --sysroot support.Father
P
10

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."

Protest answered 26/5, 2016 at 15:15 Comment(3)
Is there any solution?Suazo
it's been a while since I messed with this, but if you have --with-libs instead of --with-sysroot, use that maybe? or download another toolchain, or build your own.Protest
"If you have this directory present on your machine (maybe with a different compiler), then the --sysroot may not work" I just checked it with gcc-13.1 built --with-sysroot=/ and this is not the case. --sysroot=whatever works just fine exactly as it should (and / is definitely present on my machine).Fictitious
C
0

Another thing to check for - some build projects sneak in -nostdinc option to compiler arguments. It also makes the build to ignore sysroot includes.

Connors answered 13/6, 2024 at 21:36 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.