How to deal with linker error - error - "cannot find -lgcc"
Asked Answered
C

2

22

This is my makefile:

task0 : main.o numbers.o add.o
        gcc -m32 -g -Wall -o task0 main.o numbers.o add.o

main.o : main.c
        gcc -g -Wall -m32 -ansi -c -o main.c
numbers.o : numbers.c
             gcc -g -Wall -m32 -ansi -c -o numbers.c
add.o: add.s
      nasm -g -f elf -w+all -o add.o add.s
clean :
        rm -f *.o task0

And this is the terminal output:

gcc -m32 -g -Wall -o task0 main.o numbers.o add.o

Output:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a when      searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
make: *** [task0] 1 הלקת

What is lgcc and how can I fix that?

Collbaith answered 3/3, 2014 at 21:4 Comment(3)
You should install the gcc-multilib packageJimmie
askubuntu.com/questions/250910/…Larsen
This is the subject of a meta question.Costume
C
24

(Answered in a comment. See Question with no answers, but issue solved in the comments (or extended in chat) )

@Basil Starynkevitch wrote:

You should install the gcc-multilib package

@Jekyll wrote:

https://askubuntu.com/questions/250910/cross-compilation-issues-with-gcc-g

Corder answered 3/3, 2014 at 21:4 Comment(2)
Credit should be given, but I suggest rewriting the answer to be a complete and comprehensive answer. The meta information ought to be at the very end; most readers are not interested in it. It may also be considered that one of the commenters has been suspended for excessive self promotion (several times even)—I don't know if it is the case here.Costume
this answer does not shows : "What is lgcc" ?Icj
S
0

For those using compilers installed at a location other than /usr/bin/ it may be necessary to set the sysroot for the architecture you are targeting.

For example, this:

echo "int main() { return 0; }" > main.c

/arm/4.x/sysroot/x86_64-yodasdk-linux/usr/bin/aarch64-poky-linux/gcc  \
    -mcpu=cortex-a53  -o test_armv8a  main.c

returns:

real-ld: cannot find Scrt1.o: No such file or directory
real-ld: cannot find crti.o: No such file or directory
real-ld: cannot find crtbeginS.o: No such file or directory
real-ld: cannot find -lgcc
real-ld: cannot find -lgcc_s
real-ld: cannot find -lc
real-ld: cannot find -lgcc
real-ld: cannot find -lgcc_s
real-ld: cannot find crtendS.o: No such file or directory
real-ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

Searching for the standard libraries with:

find /arm/4.x/ -name *gcc*.so 2>/dev/null

returns:

/arm/4.x/sysroots/aarch64-poky-linux/lib/libgcc_s.so
/arm/4.x/sysroots/x86_64-yodasdk-linux/lib/libgcc_s.so

So the libraries for the target device can be specified by compiling with:

/arm/4.x/sysroot/x86_64-yodasdk-linux/usr/bin/aarch64-poky-linux/gcc  \
    --sysroot /arm/4.x/sysroot/aarch64-poky-linux/  \
    -mcpu=cortex-a53  -o test_armv8a  main.c

Or via make: CFLAGS="--sysroot /arm/4.x/sysroot/aarch64-poky-linux/"

Or via cmake: set(CMAKE_SYSROOT "/arm/4.x/sysroot/aarch64-poky-linux/" )

https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html#index-sysroot

Sanburn answered 3/11, 2023 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.