C语言预处理之多文件编译

C语言预处理之多文件编译

mkdir mutil_files
	//多文件
cd mkdir mutil_files
touch main.c
	//主函数文件
mkdir header
	//存放自定义的头文件
mkdir source
	//存放源文件
mkdir output
	//输出的可执行文件
cd header 
	code test,h
		#ifndef _TEST_H_
		#define _TEST_H_
		#program once
			不管这个头文件被包含了多少次,只进行一次编译解析
		#include<stdio,h>
		void test_print_message();
			//定义一个函数原型
		# endif
	code max.h
		#ifndef _MAX_H_
		#define _MAX_H_
		int  max_int_two (int a,int b);
		#endif
	cd ../source
 code test.c
	#include<stdio,h>
	void test_print_message(){
		//定义一个函数原型
	printf("这是一段测试的代码");
	}
code max.c
	int  max_int_two (int a,int b){
	return a>b?a:b;
	}
	cd ..
	
code main.c
	#include"header/test,h"
	#include"header/max.h"
	//链接过程中需要链接多个文件,o
		函数虽然定义了但找不到其实现,故而错误
		每一个源文件都会生成一个目标文件
	int main(){
		//不管编译的文件有多少个,一个c程序中,main函数只能出现一个
	void test_print_message();
	return 0;
	}
gcc main.c source/test.c source/max.c -o output /result
	//编译
output /result
	输出

创建脚本

	code build.sh
	gcc main.c source/test.c source/max.c -o output /result
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值