【Linux】自动生成makefile(ubuntu)

article/2025/10/31 2:53:14

文章目录

  • 前言
  • 一、Automake工具
  • 二、具体步骤
    • 1.下载Automake
    • 2.autoscan
    • 3.重命名configure.scan为configure.ac
    • 4.修改重命名后的configure.ac
    • 5.执行aclocal命令
    • 6.autoheader
    • 7.autoconf
    • 8.创建Makefile.am
    • 9.automake
    • 10.执行configure
    • 11.执行make
    • 12.执行Makefile编译完生成的可执行文件
  • 总结


前言

菜鸟第一次试水写博客,请多关照!`

因为一些个人需要,所以跑去研究了一下“如何自动生成一个Makefile”。之后要写的一个工程可能代码量会大一些,再加之本身对Makefile的了解没有太多,所以想摸鱼用自动生成makefile工具玩一玩。
本文以ubuntu16.04及automake工具为例。


提示:以下是本篇文章正文内容,下列步骤可供参考

一、Automake工具

GNU Automake 是一个自动生成符合 GNU 编码标准的 Makefile.in 文件的工具。(本句from 百度,还有很多其他的工具,这里就不做讨论了(毕竟也没用过其他的))

二、具体步骤

1.下载Automake

在使用之前可以先用automake命令试看看是否有下载automake工具:
如果有下载:(如下所示)
【ps:命令请只看~/test_03_automake001$ 之后的语句】

book@100ask:~/test_03_automake001$ automake
automake: error: 'configure.ac' is required

【此处提示也表示了 执行自动生成makefile命令需要文件“configure.ac”】
如果显示“command not found ”就代表没有下载,(以ubuntu为例)可以执行下面这个命令进行下载

sudo apt install automake

2.autoscan

因为自动生成makefile需要 ‘configure.ac’ ,所以我们先用autoscan命令生成configure.scan,
再将configure.scan重命名为configure.ac
【ps:此处使用“tree”命令仅仅是个人习惯(看文件比较清晰,也可以使用ls命令来查看)】
【pss:同理可得,也可以通过sudo apt install tree命令 在ubuntu下载tree】
【psss:除了configure.scan,还生成了autoscan.log。这是automake的日志文件】
代码如下(示例):

book@100ask:~/test_03_automake001$ autoscan
book@100ask:~/test_03_automake001$ tree
.
├── autoscan.log
├── configure.scan
└── hello.c0 directories, 3 files

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

上一个步骤已经用autoscan命令生成了configure.scan,
那么此时就需要将configure.scan重命名为configure.ac
【ps:此处使用“tree”命令仅仅是个人习惯】
重命名代码如下(示例):

book@100ask:~/test_03_automake001$ mv configure.scan configure.ac 
book@100ask:~/test_03_automake001$ tree
.
├── autoscan.log
├── configure.ac
└── hello.c0 directories, 3 files

4.修改重命名后的configure.ac

在这一步反复栽跟头的我(QAQ)……

  • 先看看文件里是啥吧(初始文件代码如图所示(我偷偷加点中文注释不过分吧==))
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
#使用 autoconf 处理此文件以生成配置脚本#AC_PREREQ([2.69])                                              #最新版本#           
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])  #三个参数:包名,版本名,邮箱地址#
AC_CONFIG_SRCDIR([hello.c])				                       #指定属于项目的文件(通常是源文件)#
AC_CONFIG_HEADERS([config.h])								   #创建一个 config.h 文件,收集由 configure.ac 中其他的“#define”## Checks for programs.
AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_OUTPUT
~                                                                               
~                                                                               
~            
  • 下面为修改完的configure.ac文件
# Process this file with autoconf to produce a configure script.AC_PREREQ([2.69])
AC_INIT(test_03_001, 1.0, 101255983@qq.com)
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])
#添加了这一行↓  
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
#(如果你想用AM_INIT_AUTOMAKE(test_03_001, 1.0)就把AC_init删掉,如果不想删就只写AM_INIT_AUTOMAKE就好# Checks for programs.
AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.#还添加了这一行 注意不要在括号前加空格(出错了就巨难找)
AC_CONFIG_FILES([Makefile])  
AC_OUTPUT#由 AC_CONFIG_FILES 创建的文件

5.执行aclocal命令

  • 生成aclocal.m4文件
    【ps:生成了很多文件 眼花缭乱警告TAT】
book@100ask:~/test_03_automake001$ aclocal
book@100ask:~/test_03_automake001$ tree
.
├── aclocal.m4
├── autom4te.cache
│   ├── output.0
│   ├── requests
│   └── traces.0
├── autoscan.log
├── configure.ac
└── hello.c1 directory, 7 file                   

6.autoheader

生成 config.h.in configure.in文件

book@100ask:~/test_03_automake001$ autoheader
book@100ask:~/test_03_automake001$ tree
.
├── aclocal.m4
├── autom4te.cache
│   ├── output.0
│   ├── output.1
│   ├── requests
│   ├── traces.0
│   └── traces.1
├── autoscan.log
├── config.h.in
├── configure
├── configure.ac
├── hello.c
└── Makefile.am1 directory, 12 files

7.autoconf

执行autoconf 生成 configure文件

book@100ask:~/test_03_automake001$ autoconf
book@100ask:~/test_03_automake001$ tree
.
├── aclocal.m4
├── autom4te.cache
│   ├── output.0
│   ├── output.1
│   ├── requests
│   ├── traces.0
│   └── traces.1
├── autoscan.log
├── configure
├── configure.ac
└── hello.c1 directory, 10 files

8.创建Makefile.am

Makefile.am 文件如下所示

bin_PROGRAMS = test_03 			  //生成的可执行文件 为test_03
test_03_SOURCES = hello.c			//源文件为hello.c

9.automake

  • 直接执行automake发现出错 出错提示如下所示:

(缺少一些文件 以及 configure.ac中的 AC_CONFIG_FILES([Makefile]) 有误)
检查发现:AC_CONFIG_FILES([Makefile])括号前多加了一个空格

book@100ask:~/test_03_automake001$ automake
automake: warnings are treated as errors
configure.ac:23: warning: not enough arguments for AC_CONFIG_FILES
configure.ac:13: error: required file './compile' not found
configure.ac:13:   'automake --add-missing' can install 'compile'
configure.ac:9: error: required file './install-sh' not found
configure.ac:9:   'automake --add-missing' can install 'install-sh'
configure.ac:9: error: required file './missing' not found
configure.ac:9:   'automake --add-missing' can install 'missing'
automake: error: no 'Makefile.am' found for any configure output
automake: Did you forget AC_CONFIG_FILES([Makefile]) in configure.ac?

文件缺少的问题可以通过

  1. 执行出错信息里提示的命令automake --add-missing得到补充

2.手工创建,运用touch命令 例如touch compile depcomp install-sh missing
(ps:如果出现Permission denied就用sudo su root转换成root用户就可了)

然后再次执行

automake

autoconf

(生成配置文件 configure)
【事实上我觉着autoconf 起到更新configure的作用】


10.执行configure

执行情况如下:(直接打 ./configure就行)

book@100ask:~/test_03_automake001$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands

执行完通过 tree命令 (或者ls命令查看是否生成Makefile文件)

如图所示 得到Makefile文件啦!!


11.执行make

这步没啥好写的直接敲make就是了


12.执行Makefile编译完生成的可执行文件

(还记得在Makefile.am里写的可执行文件名吗?……执行它就对了)
执行效果如图所示
(下面是hello.c的代码 印证一下makefile有正确执行→_→)

附上hello.c的代码

总结

yep!终于写完了。
第一次试水写博客,也是因为自己折腾了一天,终于站在了巨人的肩膀上完成了automake初体验,鉴于个人糟糕的记忆力,还是写个博客记录比较靠谱。然后也希望可以帮助到一些有需要的朋友们。
学艺不精,若有不足,欢迎指教讨论~请多关照!

  • automake参考文档

https://www.gnu.org/software/automake/manual/automake.html

  • 知乎专栏

https://zhuanlan.zhihu.com/p/466365720

  • CSDN参考博客

https://blog.csdn.net/yygydjkthh/article/details/43197031
https://blog.csdn.net/snowpiaop/article/details/52998027


http://chatgpt.dhexx.cn/article/GMV2qZ9m.shtml

相关文章

【Linux】基础IO —— 下(实现动静态库)

🎇Linux:基础IO 博客主页:一起去看日落吗分享博主的在Linux中学习到的知识和遇到的问题博主的能力有限,出现错误希望大家不吝赐教分享给大家一句我很喜欢的话: 看似不起波澜的日复一日,一定会在某一天让你看…

【Linux】第九章 动态库和静态库(生成原理+生成和使用+动态链接)

🏆个人主页:企鹅不叫的博客 ​ 🌈专栏 C语言初阶和进阶C项目Leetcode刷题初阶数据结构与算法C初阶和进阶《深入理解计算机操作系统》《高质量C/C编程》Linux ⭐️ 博主码云gitee链接:代码仓库地址 ⚡若有帮助可以【关注点赞收藏】…

Linux——自动化编译(make的使用)、库文件(静态库和共享库的使用)

一、make的使用(自动化编译) make是Linux上的工程管理工具,可以实现自动化编译;make可以提高我们的编译效率。 1.安装make 命令:sudo apt install make 2.make的用法 (1)创建makefile文件&am…

rpc系列-ZooKeeper

一.简介 Zookeeper是一个分布式协调服务,就是为用户的分布式应用程序提供协调服务。 Zookeeper本身就是一个分布式程序(只要有半数以上节点存活,zk就能正常服务)。 Zookeeper所提供的服务涵盖:主从协调、服务器节点…

HBase 一文读懂

本文基于《尚硅谷大数据技术之HBase》编写。 HBase 简介 HBase定义 HBase是一种分布式、可扩展、支持海量数据存储的NoSQL数据库。 HBase数据模型 HBase的数据模型同关系型数据库(RDMS)很类似,数据存储在一张表中,有行有列。但从H…

Zookeeper学习

文章目录 今日目标apache zookeeperzookeeper的概念分布式和集群的理解zookeeper的集群架构和角色zookeeper的5大特性部署zookeeper集群环境计算机集群的安装部署三台节点(克隆两台)配置节点内存和CPUzookeeper安装 zookeeper的数据模型zookeeper的节点类…

Redission和Zookeeper分别实现分布式锁

Redission和Zookeeper分别实现分布式锁(windows) 1、Redission实现分布式事务 1.1 前提准备 下载好nginx(windows版本)下载好Jmeter(模仿高并发)下载好redis(windows版) 1.2 代码…

Zookeeper 客户端之基本操作指令

ZooKeeper命令行工具类似于Linux的shell环境,不过功能肯定不及shell啦,但是使用它我们可以简单的对ZooKeeper进行访问,数据创建,数据修改等操作. 命令行工具的一些简单操作如下: zkCli.sh客户端连接命令 ls 与 ls2 命…

kafka内置zookeeper启动失败报错INFO ZooKeeper audit is disabled. (org.apache.zookeeper.audit.ZKAuditProvider)

kafka内置zookeeper启动失败报错INFO ZooKeeper audit is disabled.(org.apache.zookeeper.audit.ZKAuditProvider)2022年新版win10安装kafka 安装配置kafka,在启动zookeeper时报错ZooKeeper audit is disabled 原因分析: 寻找资料发现是zookeeper设置参…

zookeeper日志及快照清理操作

事务日志可视化转换 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #!/bin/sh # scriptname: zkLog2txt.sh # zookeeper事务日志为二进制格式,使用LogFormatter方法转换为可阅读的日志 if [ -z "$1" -o "$1" "-h&quo…

【RPC】注册中心实现方案之ZooKeeper

文章目录 ZooKeeper一致性协议:ZAB ZooKeeper ZooKeeper是一个开源的分布式协调服务,它可以用来协调和同步多服务器之间的状态。 ZooKeeper 可以作为微服务架构中注册中心的选型,它最需要被关心的也是数据模型和一致性协议。数据模型关乎服…

Linux 搭建zookpeer集群和配置

zookpeer和JDK1.8下载地址 下载地址:zookpeer和jdk1.8 提取码:w189 解压以及配置zookpeer tar -zxvf zookeeper-3.4.6.tar.gz tar -zxvf jdk-8u144-linux-x64.tar.gz 基本参数配置 参数描述clientPort主要定义客户端连接zookeeper server的端口&…

hadoop-zookeeper的详细介绍以及安装配置步骤

一、zookeeper的介绍 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、…

k8s-7: kafka+zookeeper的单节点与集群的持久化

之前在k8s环境中有这个需求&#xff0c;看了好多的文档&#xff0c;都有坑&#xff0c;踩了一边总结一下&#xff0c;需要的朋友可自取 一、单节点部署 建议开发环境使用&#xff0c;且此处采用动态挂载的&#xff0c;生产不建议 1、安装zk cat > zk.yaml <<EOF a…

Docker 安装Zookeeper

第一步&#xff1a;查看本地镜像和检索拉取Zookeeper 镜像 # 查看本地镜像 docker images # 检索ZooKeeper 镜像 docker search zookeeper # 拉取ZooKeeper镜像最新版本 docker pull zookeeper:latest [rootlocalhost ~]# docker images REPOSITORY TAG …

mac pro m1:搭建zookeeper集群并设置开机自启

0. 引言 之前我们讲解过搭建zookeeper单节点&#xff0c;但在实际生产中&#xff0c;为了保证服务高可用&#xff0c;通常我们是采用集群模式。所以本次我们来实操集群模式的搭建 1. zk集群模式 zk可以作为注册中心和配置中心&#xff0c;常用在微服务各类组件的多节点服务治…

一款实用的数据恢复软件—zook data recovery wizard

zook data recovery wizard是RecoveryTools下的一款子品牌&#xff0c;同时也是一款功能实用的数据恢复软件&#xff0c;该软件可以从Windows中恢复已删除&#xff0c;损坏&#xff0c;格式化和丢失的数据&#xff0c;能够支持从驱动器&#xff0c;SD卡&#xff0c;硬盘&#x…

zook 报错 Unable to read additional data from server sessionid 0x0

zook报错启动报错&#xff1a; 2017-09-25 18:33:46,913 - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread1183] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting r…

hadoop大数据集群搭设(hadoop+zook+HBase+hive)百分百成功

hadoop大数据集群搭设 前言所需软件虚拟机准备工作一、Jdk安装二、安装zookeeper三、HBase安装四、mysql安装配置五、安装hive 前言 经过长时间的测试总结出在目前集群搭建最稳定的步骤是&#xff1a; 至少我按这个过程基本0失误&#xff0c;且初始化次数最少。当然也可以尝试…

zookeeper客户端命令(三)

zookeeper客户端命令&#xff08;三&#xff09; 问题背景zookeeper分布式技术基本概念&#xff08;一&#xff09;zookeeper单机及集群部署&#xff0c;附安装包下载&#xff08;二&#xff09;zookeeper客户端命令&#xff08;三&#xff09; zook客户端指令节点创建测试集群…