Codeblocks 模块化编程
我们新建一个c工程,默认会有main.c
接下来
第一步新建 new.h new.c
第二步新建two.h two.c
注意在保存.h 和.c的时候把下面的两项编译选项都勾上
一般情况下我们可以在头文件中这么写声明,也可以使用cd自带的头文件声明
#ifndef _X_H_
#define _X_H_
#endif
下面是测试代码
MAIN.C
#include <stdio.h>
#include <stdlib.h>
#include "new.h"
#include "two.h"
int main()
{
printf("Hello world!\n");
show_one();
show_two();
return 0;
}
new.h
#ifndef NEW_H_INCLUDED
#define NEW_H_INCLUDED
extern void show_one();
#endif // NEW_H_INCLUDED
new.c
#include <stdio.h>
void show_one()
{
printf("hello, i am one!!!\n");
}
---------------------------------------------------------------------------------------
two.h
#ifndef TWO_H_INCLUDED
#define TWO_H_INCLUDED
extern void show_two();
#endif // TWO_H_INCLUDED
two.C
#include <stdio.h>
void show_two()
{
printf("hello, i am two!!!!\n");
}