前面说的
我们知道configure.ac可以生成configure文件,而Makefile.am可以生成Makefile文件,之所以这么做就是为了适应不同的环境需求,(本文)写的比较多,但是按照这个操作这个足以入门
我已经写好了一个示例,目录结构如下
# tree
.
├── a.c
├── b.c
├── b.h
├── configure.ac
├── Makefile.am
└── src
├── c.c
├── c.h
├── d.c
├── d.h
└── Makefile.am
我想在src的文件夹编译一个静态库,叫libfoo.a,基于c.c、d.c、c.h、d.h生成
我想用a.c编译一个程序叫做test,并引用了上面的 libfoo.a
代码
c文件代码(不是很重要)
// a.c
#include <stdio.h>
#include "b.h"
#include "src/c.h"
void main()
{
fun1();
fun2();
}
// b.c
#include <stdio.h>
int fun1()
{
return 1;
}
// b.h
#include <stdio.h>
int fun1();
// c.c
#include <stdio.h>
int fun2()
{
return 1;
}
// c.h
#include <stdio.h>
int fun2();
// d.c
#include <stdio.h>
int fun3()
{
return 1;
}
// d.h
#include <stdio.h>
int fun3();
configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([myproject], [1.0.0])
AC_CONFIG_SRCDIR([a.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB
AM_PROG_AR
# Checks for libraries.
AC_CHECK_LIB([curl], [curl_easy_perform], [CURL123=-lcurl], AC_MSG_ERROR("需要安装curl库"))
AC_SUBST([CURL123])
# Checks for header files.
have_openssl=yes
AC_CHECK_HEADER(openssl/sha.h, [have_openssl=yes], [have_openssl=no])
if test "x$have_openssl" != "xyes"
then
AC_MSG_ERROR("需要安装openssl库")
else
AC_MSG_WARN("else示范")
fi
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
Makefile.am (外层)
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4
bin_PROGRAMS = test
test_SOURCES = a.c b.c
noinst_HEADERS = b.h
test_LDADD = @CURL123@ src/libfoo.a
SUBDIRS = src/
#AM_CFLAGS = -L/usr/include
src/Makefile.am
lib_LIBRARIES = libfoo.a
libfoo_a_SOURCES = c.c d.c
include_HEADERS = c.h d.h
前提
假
自动生成配置脚本与Makefile:configure.ac与Makefile.am详解

本文详细介绍了如何使用configure.ac和Makefile.am文件来生成适应不同环境的configure和Makefile。通过示例展示了如何创建静态库libfoo.a和程序test,并依赖静态库。内容涵盖了configure.ac中的关键宏及其作用,以及Makefile.am的配置。还提到了编译静态库和la库的区别,以及编译过程中可能遇到的问题和解决办法。
最低0.47元/天 解锁文章
832

被折叠的 条评论
为什么被折叠?



