简体   繁体   中英

Make a small mach-o executable with C

For curiosity's sake, I'm trying to see what's the smallest that I can make a C program with a minimum of assembly language. I want to see if I can make a simple OpenGL demo (ie demo scene) using OpenGL and GLUT linked dynamically, without the standard library. However, I'm running into trouble with the most basic stuff.

I've created a test main.c file that contains

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

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

and I'm making it with

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

using the '-e' option as recommended by this StackOverflow question . 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'm running OS X 10.7 (Lion). Can anyone help me out?

For newStart() , the corresponding symbol is _newStart . You should use that for the -e option:

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

See this Stack Overflow question about why underscores are prepended to (extern) function names: Why do C compilers prepend underscores to external names?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM