GCC running mac build program?

I am trying to run the following code in the terminal on my Mac:

.section, .data

format_string:
   .asciz "My favorite number is %d!"

number:
  .long 786

.section, .text
.globl main

main:
  pushl number
 pushl $format_string  
 call printf 
  addl $8, %esp

  pushl $0
  call exit

      

This code is in a file named favorite.s

I used the command "gcc favorite.s -m32" and I see the following message:

Undefined symbols for architecture i386:
  "_main", referenced from:
      start in crt1.10.6.o
  "exit", referenced from:
      main in ccUKdD8O.o
  "printf", referenced from:
      main in ccUKdD8O.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

      

What am I doing wrong here? Thank.

+3


source to share


1 answer


Characters have an underscore added to them in Mac OS X. Add _

before main

, exit

and printf

to your program and try again!



+5


source







All Articles