使用autoscan自动生成makefile文件

本教程使用的是centos7,当前目录下有5个C文件,任务是将他们生成makefile文件

 

 文件内容如下:

复制代码
// add.c
int myadd(int a, int b)
{
    return a+b;
}

// mul.c
int mymul(int a, int b)
{
    return a*b;
}

// div.c
int mydiv(int a, int b)
{
    return a/b;
}

// x.h
int myadd(int a, int b);
int mymul(int a, int b);
int mydiv(int a, int b);

// x.c
#include <stdio.h>
#include "x.h"

int main()
{
    int a = 100;
    int b = 12;
    int add, mul, div;
    add = myadd(a, b);
    mul = mymul(a, b);
    div = mydiv(a, b);
    
    printf("%d + %d = %d\n", a, b, add);
    printf("%d * %d = %d\n", a, b, mul);
    printf("%d / %d = %d\n", a, b, div);
    
    return 0;
}
复制代码

 

1. 安装相关软件

CentOS的安装命令

sudo yum install autoconf automake

Ubuntu的安装命令

sudo apt-get install autoconf

 

2. 使用autoscan命令

autoscan

这时目录产生了两个新文件:

 

 3. 把configuire.scan重命名为configure.ac

mv configure.scan configure.ac

 

4. 修改configure.ac的文件内容

vim configure.ac

 

5. 使用aclocal命令,产生了几个新文件

aclocal

 

6. 使用autoconf命令

autoconf

 

7. 使用autoheader命令

autoheader

 

8. 编写 Makefile.am文件,写入如下信息,保存。注意Makefile.am文件中第2行、第3行中的demo与上面第4步configure.ac文件中的demo名字要一致。

vim Makefile.am
Makefile.am文件内容:
AUTOMAKE_OPTIONS=foreign bin_PROGRAMS=demo demo_SOURCES= x.c add.c mul.c div.c

 

9. 使用 automake --add-missing

automake --add-missing

 

10. 执行configure文件,此时生成了Makefile文件

./configure

 

11. 执行make,此时生成了之前设置的可执行文件demo

make

 

12. 运行生成的可执行文件demo

./demo

 

 

完成!

 

参考:https://blog.csdn.net/stoneliul/article/details/49094523

posted @   拾月凄辰  阅读(391)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示
主题色彩