Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22261

Linking a compiled assembly and C file with ld

$
0
0

I have compiled these programs:

  BITS 16
extern _main
start:
      mov ax, 07C0h 
      add ax, 288
      mov ss, ax 
      mov sp, 4096

      mov ax, 07C0h 
      mov ds, ax 

      mov si, text_string 
      call print_string 

      jmp $

      text_string db 'Calling Main Script'
      call _main

print_string:
      mov ah, 0Eh 

.repeat:
      lodsb 
      cmp al, 0
      je .done 
      int 10h
      jmp .repeat 

.done:
      ret 

      times 510-($-$$) db 0
      dw 0xAA55

and this as a test just to try linking them

int main()
{
  return 0;
}

both compile completely fine on their own using: gcc -Wall -m32 main.cnasm -f elf bootloader.asm however I cannot link them using: ld bootloader.o main.o -lc -I /lib/Id-linux.so.2 and I get this error:

ld: i386 architecture of input file `bootloader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `main.o' is incompatible with i386:x86-64 output
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000
ld: bootloader.o: file class ELFCLASS32 incompatible with ELFCLASS64
ld: final link failed: file in wrong format

Any help would be great thanks


Viewing all articles
Browse latest Browse all 22261


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>