基本认识:
#include <xxx>:首先去系统目录中找头文件,如果没有在到当前目录下找。像标准的头文件 stdio.h、stdlib.h等用这个方法。
#include “xxx”:首先在当前目录下寻找,如果找不到,再到系统目录中寻找。 这个用于include自定义的头文件,让系统优先使用当前目录中定义的。
单个.c源文件:test.c
/*=====test.c=======*/
#include <stdio.h> int main(void)
{
printf("Hello, world!\n");
return ;
}
gcc -g test.c -o test
-g:为了GDB调试加入的参数;
./test
多个源文件: main.c hello.h hello.c
/*=====main.c=======*/
#include <stdio.h> #include "hello.h" int main() { hello(); return ; }
/*===hello.h=======*/
void hello();
/*====hello.c=======*/
#include <stdio.h>
#include "hello.h"
void hello() {
printf("Hello,world!.\n"); }
gcc main.c hello.c -o main
./main