In function `_start':(.text+0x****): undefined reference to `main'....
例如:
#include <stdlib.h> #include <string.h> #include <stdio.h> void test() { char* str = (char*)malloc(100); strcpy(str,"hello"); //free(str); if(str != NULL) { strcpy(str, "world"); } printf("%s",str); } int main(int argc, char *argv[]) { test(); return 0; }
编写对应的makefile文件:(或者直接bash语句编译)
test:test.c gcc-g -o test test.c
编译时会出现如下error:
/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start': (.text+0xc): undefined reference to `__libc_csu_fini' /usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start': (.text+0x11): undefined reference to `__libc_csu_init' collect2: ld returned 1 exit status make: *** [test] Error 1解决方案
这是没有使用了共享库,没有链接,添加了-shared选项之后,即可:
gcc -shared -g -o test test.c