教你玩Makefile(二)

21 篇文章 0 订阅
20 篇文章 0 订阅

教你玩Makefile(一)

教你玩Makefile(二)

教你玩Makefile(三)

接着上一张《教你玩Makefile(一)

这一张主要是使用的autotools:

一、先安装autotools;

sudo yum install autoconf automake

二、autotools的步骤:

        autoscan
		mv configure.scan  configure.ac
	vim Makefile.am
	aclocal
	autoheader
	autoconf
	automake --add-missing
	./configure 
	make 
        make install

三、接下来来个实例:

hello_ffmpeg.c

/*************************************************************************
	> File Name: hello_ffmpeg.c
	> Author: yinshangqing
	> Mail: 841668821@qq.com 
	> Created Time: Wed 14 Mar 2018 11:09:34 PM EDT
 ************************************************************************/

#include <stdio.h>
  
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavdevice/avdevice.h>
 
  
int main()
{
	printf("Hello FFmpeg!");
	av_register_all();
	unsigned int version = avcodec_version(); 
	printf("version is: %d\n", version);

	return 0;
}

普通的Makefile如下:

.PHONY:clean all
CC=gcc
CFLAGS=-Wall -g  -Iffmpeg/include -Lffmpeg/lib/ -lavdevice -lavformat -lavfilter -lavcodec -lswscale -lavutil -lswresample
BIN=hello_ffmpeg
all:$(BIN)
%.o:%.c%.h
	$(CC) $(CFLAGS) -c $< -o $@
clean:
		rm -f *.o $(BIN)

使用autotools工具来生成Makefile,如下:

1、使用autoscan命令生成configure.scan

2、将configure.scan修改为configure.ac(老版的是configure.in)。使用mv configure.scan configure.ac

3、修改configure.ac,下面是原本生成的,由 AC_PREREQ([2.69])可以看出我的版本是2.69的。

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([hello_ffmpeg.c])
AC_CONFIG_HEADERS([config.h])

# 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文件:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([hello_ffmpeg.c], [1.0], [841668821@qq.com])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_CONFIG_SRCDIR([hello_ffmpeg.c])
AC_CONFIG_HEADERS([config.h])
# 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_INIT([hello_ffmpeg.c], [1.0], [841668821@qq.com]) 中的hello_ffmpeg.c是相当于一个项目中的main.cpp。后面一次是版本和接收bug的邮箱。

4、vim Makefile.am

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello_ffmpeg
hello_ffmpeg_SOURCES=hello_ffmpeg.c      #(所有的相关的文件)
#play_ffmpeg_LDADD=     # 应用静态库的位置                                                           
hello_ffmpeg_LDFLAGS=-Lffmpeg/lib/ -lavdevice -lavformat -lavfilter -lavcodec -lswscale -lavutil -lswresample
hello_ffmpeg_CFLAGS=-Iffmpeg/include -O2 -g   #  头文件

在这里配置工程。

5、一路命令下去:

    aclocal-->autoheader->autoconf->automake --add-missing

这时会生成一个可以执行的configure,运行这个configure会生成Makefile


这时,已经生成了我们所需要的Makefile,

make一下,便会生成我们需要的hello_ffmpeg的可执行的文件:



上图中生成的hello_ffmpeg运行结果,使用make install 需要管理员权限,这样安装后,便可以直接运行了。

使用make uninstall 来删掉再/usr/local/bin目录下的hello_ffmpeg文件(这里同样需要管理员权限)。

到此,这个工程就完成了!!!

下一篇《 教你玩Makefile(三)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值