This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

arm-linux-gnueabihf: gcc and ld problem with --sysroot option

I recently downloaded the latest version of the SDK for the AM335x processor and it came with a newer version of the compiler it uses: arm-linux-gnueabihf replaces the old arm-arago-linux-gnueabi.

What changed is that now I have to inform the gcc where the headers and libraries are with the option --sysroot=<directory>. The Makefile I use first generate all the objects with -c option and then it links them. The thing is, in the last step of the build process, when I use

$(CC) -Wl,--sysroot=$(SDK_PATH_TARGET) -o $(OBJDIR)/$(TARGET) $(ALLOBJ)

the linker complains it does not find some libraries, but if I change the command to the one below the linker finds everything:

$(CC) --sysroot=$(SDK_PATH_TARGET) -o $(OBJDIR)/$(TARGET) $(ALLOBJ)

So I was wondering why the heck -Wl doesn't works as I think it should. Does that mean the option --sysroot differs from the gcc and the ld programs? The help of the commands weren't clear enough:

$ ./arm-linux-gnueabihf-gcc --help | grep "sysroot="
--sysroot=<directory> Use <directory> as the root directory for headers and libraries

$ ./arm-linux-gnueabihf-ld --help | grep "sysroot="
--sysroot=<DIRECTORY> Override the default sysroot location

So I thought someone here would explain when to use -Wl,--sysroot=<directory> and when to use --sysroot=<directory> as options to the gcc!

Thanks.

DAVI

  • The TI C/C++ Compiler forum is primarily about TI compilers, though we are starting to cover the Linaro gcc ARM compiler which ships with CCS.  Unfortunately, that is not the ARM compiler you are using.

    Since they are both gcc compilers I looked into it anyway.  I used the Linaro compiler as a proxy for yours.  I cannot reproduce your issue.  According to the documentation on --sysroot I found, both forms should work equally well at finding libraries (but not header files).  That -Wl,--sysroot fails to find your libraries is something I cannot explain.

    Thus, I am moving this thread to the Sitara ARM processors forum.

    Thanks and regards,

    -George

  • Sorry for posting in the wrong place...

    So, let me be really specific then. Since my helloworld program shows this issue, maybe it will be easier to reproduce it if I show all the steps. The only thing I changed from the SDK's installation is where the folder linux-devkit is located: I placed it in the /opt/ directory·

    Helloworld.c:

    #include <stdio.h>
    #include <stdlib.h>
    int main(void)
    {
    printf("\nHello, world!\n\n");
     return EXIT_SUCCESS;
    }

    Jumping to the command line:

    $ export PATH=/opt/linux-devkit/sysroots/i686-arago-linux/usr/bin/:$PATH

    $ arm-linux-gnueabihf-gcc -c -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/linux-devkit/sysroots/armv7ahf-vfp-neon-3.2-oe-linux-gnueabi -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -fomit-frame-pointer -g0 -O2 helloworld.c -o helloworld.o

    $ arm-linux-gnueabihf-gcc -Wl,--sysroot=/opt/linux-devkit/sysroots/armv7ahf-vfp-neon-3.2-oe-linux-gnueabi -o helloworld helloworld.o
    /opt/linux-devkit/sysroots/i686-arago-linux/usr/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crt1.o: No such file or directory
    /opt/linux-devkit/sysroots/i686-arago-linux/usr/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crti.o: No such file or directory
    collect2: error: ld returned 1 exit status

    $ arm-linux-gnueabihf-gcc --sysroot=/opt/linux-devkit/sysroots/armv7ahf-vfp-neon-3.2-oe-linux-gnueabi -o helloworld helloworld.o (this one works)

    So, there is a couple things to say: I copied the CFLAGS used in the environment setup file (in my case it is located in /opt/linux-devkit/environment-setup), hence some of the options besides -c the first time I call the gcc. The other thing is that I thought it would be simpler to show the commands instead of the Makefile file I use -- I know the -c option could be left out here.

    Well, hope anyone else get this same behave! 

    DAVI

  • I think I found out why -Wl isn't supporting the --sysroot option:

    Previously, I didn't notice that there is another part to the help under the option --target-help when I said I tried the ---help of arm-linux-gnueabihf-gcc. When I type

    $ arm-linux-gnueabihf-gcc --target-help

    there is a section that list the linker options one can pass via -Wl and in this list there is no mention to --sysroot anywhere.

    That means maybe the assumption that arm-linux-gnueabihf-gcc calls arm-linux-gnueabihf-ld passing everything in -Wl is wrong...

    It would be very helpful if anyone could verify if that is the case, because --target-help is supposed to be target specific, would it make any sense to display all the -Wl option there?

    Thanks!

    DAVI

  • Obs: /opt/linux-devkit/sysroots/i686-arago-linux/usr/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld (the one showed in red in my example) and arm-linux-gnueabihf-ld are the same binary file...

  • Hi,

        Can you please mention the way i need to compile an C++ application using   arm-linux-gnueabihf-g++

    guest@ubuntu:~$ arm-linux-gnueabihf-g++ --sysroot=/mnt/build/linux-devkit/sysroots/armv7ahf-vfp-neon-3.2-oe-linux-gnueabi hello.cpp


    hello.cpp:1:19: fatal error: iostream: No such file or directory
    compilation terminated.


  • You will have to change the paths I use, but here is a command that tricks the compiler into looking for the right folders...

    $ arm-linux-gnueabihf-g++ -c -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/linux-devkit/sysroots/armv7ahf-vfp-neon-3.2-oe-linux-gnueabi -Wall -Wextra -fomit-frame-pointer -g0 -O2 -I/opt/linux-devkit/sysroots/armv7ahf-vfp-neon-3.2-oe-linux-gnueabi/include/c++/4.7.3 -I/opt/linux-devkit/sysroots/armv7ahf-vfp-neon-3.2-oe-linux-gnueabi/include/c++/4.7.3/arm-linux-gnueabihf/arm-linux-gnueabi/  a.cpp -o a.o

    $ arm-linux-gnueabihf-g++ --sysroot=/opt/linux-devkit/sysroots/armv7ahf-vfp-neon-3.2-oe-linux-gnueabi -o a a.o

    Et voilà. I really think this new compiler complicate things and there is no documentation so far. TI should at least compile a hello world example and post it on the wiki to help us...

    DAVI

  • You will also have to change the filesystem you use (if you haven't done so yet). Use the one that comes with the new SDK, changing the GCC version forces you to recompile EVERYTHING...

  • I ran into this same issue.

    This is happening because the installer creates absolute symbolic links in to directories in linux-devkit/sysroots/i686-arago-linux/ that point to lib, include, etc in the sysroot (armv7ahf-vfp-neon-3.2-oe-linux-gnueabi).


    If the installer instead created symbolic links that were relative instead of absolute, one wouldn't run into this problem.

    You can find out which symbolic links are broken if you execute this command in the linux-devkit directory:

    find . -type l -xtype l

  • So simple and I never thought into look for this. Thank you! :-)


    DAVI