Make a small mach-o executable with C

For curiosity, I'm trying to understand that the smallest thing I can do is a C program with a minimal assembly language. I want to see if I can do a simple OpenGL demo (i.e. Demo scene) using OpenGL and GLUT dynamically, without a standard library. However, I ran into problems with the most basic things.

I created a main.c test file containing

void newStart() {
  //Do stuff here...

  asm("movl $1, %eax;"
      "xorl %ebx, %ebx;"
      "int  $0x80;");
}

and I do it with

gcc main.c -nostdlib -e newStart -o min

using the '-e' option, as recommended qaru.site/questions/1092699 / ... . I get the following error when I try to compile it:

ld: warning: symbol dyld_stub_binder not found, normally in libSystem.dylib
ld: entry point (newStart) undefined. for architecture x86_64

I am running OS X 10.7 (Lion). Can anyone help me out?

+5
1

newStart() _newStart. -e:

gcc main.c -nostdlib -e _newStart -o min

. , (extern): C ?

+3

All Articles