0

I'm trying to compile a c code as 32 bit on a x64 machine. using gcc -m32. But I'm getting the following errors

pegasus@pegasus:~/Documents/CSE21_workshop$ gcc -m32 got_plt.c 
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory
collect2: error: ld returned 1 exit status

I had already installed g++-multilib and gcc-multilib. My current gcc version:

pegasus@pegasus:~$ gcc --version
gcc (Ubuntu 8.4.0-3ubuntu2) 8.4.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
NobinPegasus
  • 545
  • 2
  • 16
  • Those are all linker errors. Possibly duplicate https://stackoverflow.com/questions/3501878/force-gcc-to-compile-32-bit-programs-on-64-bit-platform may provide an answer (the comments to the accepted answer are relevant to your issue I think). Also confirmed elsewhere (by searching using the error messages as a search term), install gcc-multilib (and g++-multilib for c++ support). – Clifford May 27 '23 at 19:30
  • I had already gone through. It but I'm just compiling a single basic C file. Don't think using Cmake or Makefile will be wise. I just wanna use the -m32 flag error freely. Also I had added my gcc version. Is having multiple gcc a problem? – NobinPegasus May 27 '23 at 19:34
  • Who said anything about using cmake? The part that I took from that is the need to install gcc-multilib (and g++-multilib for c++ support). I updated the comment you were responding to BTW, it now includes that clarification. See also https://www.baeldung.com/linux/compile-32-bit-binary-on-64-bit-os – Clifford May 27 '23 at 19:36
  • Read my post first. I said I had already installed gcc-multilib and g++-multilib – NobinPegasus May 27 '23 at 19:48
  • [How to print the ld(linker) search path](https://stackoverflow.com/questions/9922949/how-to-print-the-ldlinker-search-path) may help to figure out where it is, and isn't, looking for libraries. – Retired Ninja May 27 '23 at 19:56

1 Answers1

0

Solved it. Like I mentioned I had multiple gcc installed. And it was causing error. I removed all gcc versions except one. gcc 11.3.0 It's working fine.

NobinPegasus
  • 545
  • 2
  • 16