After compiling x86 assembly code, get gcc linker error on Centos 7

phoffric
phoffric used Ask the Experts™
on
OS: Centos 7
Following tutorial @5:00: https://www.youtube.com/watch?v=KgfljMtrKkI
I get a linker error after compiling this code. What steps do I have to take to build this program?
The author indicated that this is for 32-bit code; and later he may do a series on 64-bit. I am guessing that I am having a 32-bit/64-bit issue here.
I saw a comment that may shed some light:
"I had to run apt-get install gcc-multilib to compile 32 bit on ubuntu."
global main
extern printf

section .data
  msg db "Testing %i...", 0x0a, 0x00

main:
;*** prologue - preserving stack, registers, and allocating space ***
  push ebp      ; preserve caller's ebp (base pointer) value
  mov ebp, esp  ; ebp holds the top of the stack
;*** END prologue - preserving stack and allocating space ***

  push 123
  push msg
  call printf
  mov eax, 0

;*** epilogue ***
  mov esp, ebp  ; restore the top of the stack (effectively deallocates the stack)
  pop ebp       ; restore the caller's ebp value
  ret
;*** END epilogue ***

Open in new window

Configuration:
$ uname -a
Linux localhost.localdomain 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ nasm -v
NASM version 2.10.07 compiled on Jun  9 2014

$ nasm -felf -y

valid debug formats for 'elf32' output format are ('*' denotes default):
    dwarf     ELF32 (i386) dwarf debug format for Linux/Unix
  * stabs     ELF32 (i386) stabs debug format for Linux/Unix

$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)

$ whereis crt1.o
crt1: /usr/lib64/crt1.o
$ which crt1.o
/usr/bin/which: no crt1.o in (/usr/lib64:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/user/.local/bin:/home/user/bin)

Open in new window

The error:
$ nasm -f elf32 ex10.asm -o ex10.o
$ gcc -m32 ex10.o -o ex10
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I got this information, and after doing it, the program built with no errors and executed correctly.
# 32-bit (‘i386’) C library and headers
yum install libgcc.i686
yum install glibc-devel.i686

Open in new window

https://unix.stackexchange.com/questions/140280/no-32-development-library-error-after-install-glibc-devel-i686
# 32-bit (‘i386’) C library and headers
yum install libgcc.i686
yum install glibc-devel.i686

Open in new window

https://unix.stackexchange.com/questions/140280/no-32-development-library-error-after-install-glibc-devel-i686

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial