Linux GCC make文件的写法4--清晰版

本文介绍了一个简单的Makefile配置示例,用于构建一个包含多个源文件和头文件的C程序。通过该Makefile,可以方便地进行编译、链接及清理工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

包含3个文件夹,和一个文件Makefile

目录组织结构如下:

Makefile

inc/hello.h

main/main.c

src/hello.c

Makefile文件在外面,这样生成的.o和可执行文件都在外面,clean之后会很干净,结构清晰

文件内容如下:

Makefile(之所以用大写,因为make可以识别Makefile和makefile,用大写可以鲜明一些)::

# String declaration objects = main.o hello.o # Command app : $(objects) cc -o app $(objects) main.o : main/main.c hello.h cc -c main/main.c hello.o : src/hello.c stdio.h cc -c src/hello.c # Search paths vpath %.h /usr/include inc # Clean the intermediate files .PHONY : clean clean : rm app $(objects)

hello.h:

void hello(char name[]);

main.c:

#include <stdio.h> #include "../inc/hello.h" // The second hello.h should in "" int main() { hello("GCC"); printf("Haha Linux Ubuntu!/n"); return 0; }

其中,第二个包含文件,hello.h,必须要用"",如果用<>则gcc只会到系统目录下去搜索,不会到本当前目录下搜索

就是""在用户目录下,<>在系统目录下,这个在windows上不严格, 在linux里似乎很严格

hello.c:

#include <stdio.h> void hello(char name[]) { printf("Hello %s!/n", name); }

转载于:https://www.cnblogs.com/yanhc/archive/2010/03/17/2175258.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值