'Compiling 32 Bit Application on 64 Bit Linux
I'm trying to compile a program for 32 bit on a 64 bit Kali Linux operating system.
Here is my system information:
root@kali:~/Desktop# cat /proc/version
Linux version 3.18.0-kali3-amd64 ([email protected]) (gcc version 4.7.2 (Debian 4.7.2-5) ) #1 SMP Debian 3.18.6-1~kali2 (2015-03-02)
When I try to compile my C project, it cannot find -lgcc:
root@kali:~/Desktop/Project# make
cc -o libor libor.c -fno-stack-protector -z execstack -m32 -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/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.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
Note that I'm using the -m32 flag to force compilation for 32 bit.
Like suggested elsewhere, the 32 bit libraries should be installed which I did using the following command:
sudo apt-get install libc6-dev-i386
This however only changed the error message to the one seen above. I lost the previous one however I guess it no longer matters.
Please note that existing answers didn't help me so this is not a duplicate.
Solution 1:[1]
Try ensuring that your new 32-bit libraries are in the library search path. You can verify this by using the ldconfig command, and if the libraries' directories aren't listed, then use the tips in this web page: http://www.cyberciti.biz/faq/linux-setting-changing-library-path/
I don't know that the above is the cause of your problem, but it may be worth a try?
Solution 2:[2]
The problem is you likely only have the gcc for your current architecture and that's 64bit. You need the 32bit support files. For that, you need to install them
sudo apt install gcc-multilib
Once installed, run the below command to compile c-program to 32-bit binary executable
gcc -o libor libor.c -m32
Verify the binary is 32-bit or not by
file libor
Solution 3:[3]
apt-get install gcc-multilib
should do the trick.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Manyam Nandeesh Reddy |
| Solution 3 | Aydin K. |
