C语言
情况一(不需要用到.h)
- 在同目录底下调用.h里面的void无返回参数函数时,情况二是不能使用的
- 这里要先 生成 .o (涉及到静态库和动态库的引用)
编译如下:
gcc -c test.c
gcc –c snake1.c
得到两个 .o 文件,一个是snake1.o,一个是 test.o ,然后我们链接 .o 得到可执行程序
gcc snake1.o test.o -lcurses
./a.out
snake1.c
test.c
情况二
1、window和Linux环境使用情况都一样
2、在同个目录下
3、直接在.c文件应用定义头文件就可以了
例如:我在桌面目录下建立test.c和config.h,其中test.c要应用.h中定义好的变量(可以是宏定义),代码检测:
config.c
int fun1(int a,int b)
{
int c;
c=a+b;
return c;
}
config.h
#define GET 1
#define PWD 2
#define IFGO 3
#define LCD 4
#define LLS 5
#define CD 6
#define PUT 7
#define QUIT 8
#define DOFILE 9
int fun1(int a,int b);//函数声明
test.c
#include <stdio.h>
#include "config.h"//直接在.c文件应用定义头文件就可以了
int main()
{
printf("%d\n",CD);
printf("%d\n",PUT);
printf("%d\n",GET);
printf("%d\n",fun1(1,2));
return 0;
}
运行结果:
6
7
1
3
——————————————————
Process exited with return value 0
Press any key to continue . . .