你如何建立一个C程序,其中包括在Mac OS X的切入点? [英] How do you build a C program that includes the entry point on Mac OS X?
问题描述
你如何建立一个C程序,其中包括在Mac OS X?
How do you build a C program that includes the entry point on Mac OS X?
我想建立:
start() {
/* exit system call */
asm("movl $1,%eax;"
"xorl %ebx,%ebx;"
"int $0x80"
);
}
但是当我运行:
gcc -nostdlib min.c
我总是得到:
ld: could not find entry point "start" (perhaps missing crt1.o)
collect2: ld returned 1 exit status
我刚才提出的另外一个尝试,看看它所做的是运行:
The one other attempt I made just to see what it was doing was run:
gcc -nostdlib -c min.c && otool -tV min.o
和输出是:
(__TEXT,__text) section
_start:
0000000000000000 pushq %rbp
0000000000000001 movq %rsp,%rbp
0000000000000004 leave
0000000000000005 ret
所以,开始功能前从何而来的下划线?我如何prevent这种情况发生?或者更简单地说:
So where did that underscore come from before the "start" function? How do I prevent that from happening? Or more simply:
你如何建立一个C程序,其中包括在Mac OS X?
How do you build a C program that includes the entry point on Mac OS X?
谢谢,
CrazyChenz
Thanks, CrazyChenz
推荐答案
gcc的-e选项定义入口点,当你想要的入口点比启动其他的东西。这样,您就可以创建mystart()作为你的切入点。
The gcc -e option defines the entry point, when you want the entry point to be something other than start. This way you can create mystart() as you entry point.
gcc -e mystart mycode.c -o mycode
我不知道如何设置X code中的-e选项。
I do not know how to set the -e option in Xcode.
这篇关于你如何建立一个C程序,其中包括在Mac OS X的切入点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!