5

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 (i.e. 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?

Community
  • 1
  • 1
semisight
  • 914
  • 1
  • 8
  • 15

1 Answers1

3

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?

Community
  • 1
  • 1
  • Ahh, I see. Thank you so much. Unfortunately this only leads to more questions... whenever I run the program I get "Illegal Instruction: 4" (apparently a core dump). Should I open a new question for this? – semisight Nov 10 '11 at 00:36
  • 1
    @semisight Compiling it with `-arch i386` solves the illegal instruction issue. –  Nov 10 '11 at 00:40