GNU make和automake 生成makefile 实例

本文介绍了手动创建和使用automake工具自动生成makefile的方法。对于小型项目,可以直接编写makefile,而对于大型项目,推荐使用automake。文章详细阐述了automake的步骤,包括autoscan、aclocal、autoconf、automake和configure的使用,以及make和make install过程。

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

摘要:首先makefile自动化编译文件有两种方法,一种是自己动手写makefile,一种是用automake自动生成工具来生成makefile.

        大型项目,工程建议使用automake工具.

       小型项目,工程直接自己动手写就行.

      了解详细automake移步:automake自动生成makefile流程


一 ,  手动创建makefile

1.测试helloworld 小程序. 创建四个文件,分别是:main.c ; hello.c; hello.h;makefile.

--main.c

#include "hello.h"

void main()
{
	PrintfHello();
}

--hello.c

#include <stdio.h>
#include "hello.h"

void PrintfHello()
{
	printf(" Hello World!\n");
}

--hello.h

#ifndef _HELLO_H_
#define _HELLO_H_

extern void PrintfHello();
#endif

--makefile

#automake_library makefile

objects = main.o hello.o

HelloWorld:$(objects)
	cc -o HelloWorld $(objects)
$(objects):hello.h
.PHONY:clean
clean:
    -rm HelloWorld $(objects)

2.make 编译 .

3../HelloWorld 运行.




二运用autoconf,automake自动生成makefile

1.

如图所示为automake,autoconf生成makefile的过程(简化)。

                                    程序源码
                                           |
                                     autoscan*
                                           |
                                configure.scan
               

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值