Compiling 32 Bit Application on 64 Bit Linux - c

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 (debian-kernel#lists.debian.org) (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.

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?

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

apt-get install gcc-multilib
should do the trick.

Related

Issue compiling with f77 on OSX 10.11

I have been trying to run this model, written some decades ago by someone else. I've built the libraries, but when I try to actually run the program, I get the following error:
f77 -o mimics1.5 ../source/*.o trunk_hght_f.f
trunk_hght_f.f:
trunk_hght_func:
Undefined symbols for architecture x86_64:
"MAIN__", referenced from:
-u command line option
(maybe you meant: _MAIN__)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am on MacOSX 10.11, and which f77 gives /usr/local/bin/f77 and f77 -v gives back:
Cynthias-MacBook-Pro-2:input_dir cynthiag$ f77 -v
/usr/local/bin/f77 script based on f2c:
f2c (Fortran to C Translator) version 20100827.
Should f77 be in /usr/bin/instead?
ld seems to be the problem, so I followed instruction from HERE to try to solve it, but it looks like my XCode is up to date, that my libraries are built and linked (as far as I can tell), and I even reinstalled binutils to make sure ld was in teh right place, but no success.
which ld gives : /usr/bin/ld and ld -v gives:
Cynthias-MacBook-Pro-2:input_dir cynthiag$ ld -v
#(#)PROGRAM:ld PROJECT:ld64-264.3.102
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
LTO support using: LLVM version 7.3.0
I am new to fortran, so I probably messed up when setting up f77, but I've been stuck on this problem for a few days now, so any help would be greatly appreciated!
In the end, it seem like the solution for me was just to use gfortran instead of f77. This involved carefully switching all the mentions to f77 in the model (i.e. in all the Makefiles) and replacing them by gfortran.
A clean install of the libraries was then necessary, since apparently a library compiled in f77 will not be compatible with gfortran.
Finally, the model was calling on some executable without ./ which caused the model to failed.
Unfortunately, I can't give an explanation as to why f77 was failing, but gfortran was a lot easier to set up than f77/f2c and worked great, so it's probably the way to go.

Gcc collect2: fatal error: cannot find 'ld'

I'm going through the tutorial on making an OS on http://wiki.osdev.org/Bare_Bones. When I try to link boot.o and kernel.o using this command: i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc , I just get this error:
collect2: fatal error: cannot find 'ld'
compilation terminated.
I just installed fresh Ubuntu 15.10 that with gcc-5.2.1 and binutils-2.25.1 .
I have searched the internet for answers but nothing helped.
I also got once the same error during a pentest while I was trying to compile my exploit on the victim server.
In my case, the directory where the "ld" program was located had not been defined in the PATH environment variable, so I simply added it.
eg. export PATH=$PATH:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin
I had this error while hacking a remote machine and trying to use gcc to compile an exploit on the victim machine.
I simply copied the program ld to /tmp/, the working directory where i was compiling my exploit exploit.c by running
cp /usr/bin/ld /tmp/ld
followed by the original gcc compile command and the compile worked.
I searched a lot to fix this issue and nothing worked but lastly i uninstalled MinGw and reinstalled it then did edited the environment variables again and then uninstalled and reinstalled vs code extensions then it worked.

'Cannot find -lc' error when linking a program using gcc and autoconf

I'm trying to compile a program written in C. ./configure was successful, but when I did make, it gave me an error. I did make check, and it said:
gcc -g -Wall -static -o multipht multipht.o multimatch.o multiweight.o multiwrite.o multisort.o multiclean.o
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
("multipht" is the name of the program I'm trying to install.)
Could anyone tell me what the problem is?
Your system appears to not have a statically linkable C library. That's actually pretty common these days. Take off the -static flag and you should be good to go.
On Fedora, the static version of glibc is in the glibc-static package.
sudo yum -y install glibc-devel glibc-static

libpcap: 64bit machine has no compatible 32-bit libpcap library

I want to compile a .c file to 32-bit executable using gcc option -m32 with libpcap
the machine is linux 64bit fedora 16
however, I get the following error
[root#fdf source]# gcc -m32 -o test_tcp test_tcp.c -lpcap
/usr/bin/ld: skipping incompatible /usr/lib64/libpcap.so when searching for -lpcap
/usr/bin/ld: cannot find -lpcap
collect2: ld returned 1 exit status
I installed
yum install libpcap.i686
and then try to compile, but still get errors:
root#ddh-4.0# gcc -m32 -o test_tcp test_tcp.c -lpcap
/usr/bin/ld: skipping incompatible /usr/lib64/libpcap.so when searching for -lpcap
/usr/bin/ld: cannot find -lpcap
You need the development package in addition to the runtime library. So do
yum install libpcap-devel.i686

Gcc default version crashes

I working on open source GHDL project for my project purpose installed ghdl-0.29-2.143svn.4.fc16.src.rpm consisting of ghdl 0.29 and gcc 4.3.4 through rpm -i and rpmbuild -ba command successfully.
In ghdl folder, I edited one ada program then I did make and make install : no errors but it creates problem changes in gcc version 4.6.3 (default) to 4.3.4 and no gcc program execution gave error:
error: C compiler cannot create executables
See `config.log' for more details."
In config.log file /usr/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
Thanks in advance
Regards
Raghu
Have you tried reinstalling glibc? That might work.

Resources