Im trying to compile a nasm x86 assembly program that uses the c library. The code is
section .text
global main
extern printf
main:
push msg
mov eax, 0
call printf
add esp, 4
ret
section .data
msg db "Hello", 0xa, 0
Its a simple program that should print "Hello". Im trying to compile this with 2 commands
nasm -f elf main.asm
gcc -m32 -o main main.o
However, running gcc -m32 -o main main.o
gives some errors.
The errors are:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: cannot find libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/libgcc_s.so.1 when searching for libgcc_s.so.1
collect2: error: ld returned 1 exit status
I tried to install gcc-multilib
because I heard that it helps but I kept getting the same error. Ive also tried updating gcc but that also did not help anything.
EDIT: I fixed the errors! I had to install a 32 bit gcc library called lib32-gcc-libs
and then it got fixed. However I still have 2 warnings.
main.o: warning: relocation in read-only section '.text'
warning: creating DT_TEXTREL in a PIE
What do these warnings mean and how do I fix them?