·gcc编译器有许多选项,一般来说我们只要知道其 中的几个就够了.-0选项我们已经知道了,表示我 们要求输出的可执行文件名.-c选项表示我们只要 求编译器输出目标代码,而不必要输出可执行文 件.-g选项表示我们要求编译器在编译的时候提供 我们以后对程序进行调试的信息 知道了这三个选项我们就可以编译我们自己所写 的简单的源程序了,如果你想要知道更多的选项可 以查看gcc的帮助文档,那里有着许多对其它选项 的详细说明
• gcc编译器有许多选项,一般来说我们只要知道其 中的几个就够了. -o选项我们已经知道了,表示我 们要求输出的可执行文件名. -c选项表示我们只要 求编译器输出目标代码,而不必要输出可执行文 件. -g选项表示我们要求编译器在编译的时候提供 我们以后对程序进行调试的信息. 知道了这三个选项,我们就可以编译我们自己所写 的简单的源程序了,如果你想要知道更多的选项,可 以查看gcc的帮助文档,那里有着许多对其它选项 的详细说明
2 Makefile的编写 假设我们有下面这样的一个程序源代码如下: /s main. c Include"mytoollh Include"mytool2h int main(int argc, char **arg) mytooll_print( hello mytool2_print( hello
• 2.Makefile的编写 假设我们有下面这样的一个程序,源代码如下: /* main.c */ #include "mytool1.h" #include "mytool2.h" int main(int argc,char **argv) { mytool1_print("hello"); mytool2_print("hello"); }
·/* mytool1.h #ifndef mytool 1 h define mytool 1 h void mytooll_print(char *print_str); iendif mtool.c ifincludemytoollh void mytooll_print(char*print_str) printf("This is mytooll print %sIn", print str)
• /* mytool1.h */ #ifndef _MYTOOL_1_H #define _MYTOOL_1_H void mytool1_print(char *print_str); #endif /* mytool1.c */ #include "mytool1.h" void mytool1_print(char *print_str) { printf("This is mytool1 print %s\n",print_str); }
/*mytool2h*/ ifndef mytool 2 h define MYTooL 2 H void mytool2-_print(char *print str) fendi
• /* mytool2.h */ #ifndef _MYTOOL_2_H #define _MYTOOL_2_H void mytool2_print(char *print_str); #endif
/ mytool2C*/ include"mytool2h void mytool2_ print(char *print str) printf( this is mytool2 print %sIn", pri nt str)
• /* mytool2.c */ #include "mytool2.h" void mytool2_print(char *print_str) { printf("This is mytool2 print %s\n",pri nt_str); }