automake创建动态库

1.建立如下目录:

libmessage

├── examples/

│   ├── Makefile.am

│   ├── test.c

├── include/

│   └── zk_message.h

├── _install/

├── m4/

├── Makefile.am

└── src

   ├── Makefile.am

   └── zk_message.c

src 为库资源,include 为头文件 examples为测试程序

2.0 建立Makefile.am

ACLOCAL_AMFLAGS=-I m4

SUBDIRS=src examples

 

2.1在src建立Makefile.am

AUTOMAKE_OPTIONS=foreign

lib_LTLIBRARIES = libmessage.la

libmessage_la_SOURCES=zk_message.c

libmessage_la_CPPFLAGS=-I ../include

include_HEADERS=../include/zk_message.h

libmessage_la_LIBADD= -lpthread

 

 

2.2在examples建立Makefile.am

AUTOMAKE_OPTIONS=foreign

bin_PROGRAMS= test

 

test_SOURCES=test.c

test_CPPFLAGS=-I ../include/

test_LDADD=-L../src/.libs/ -lmessage

 

 

3.使用autoscan生成configure.scan文件,将其重命名为configure.ac

vi打开configure.ac

将:

# -*- 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([src/zk_message.c])

AC_CONFIG_HEADERS([config.h])

 

# Checks for programs.

AC_PROG_CC

 

# Checks for libraries.

# FIXME: Replace `main' with a function in `-lmessage':

AC_CHECK_LIB([message], [main])

# FIXME: Replace `main' with a function in `-lpthread':

AC_CHECK_LIB([pthread], [main])

 

# Checks for header files.

AC_CHECK_HEADERS([stdlib.h string.h unistd.h])

 

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_FUNC_MALLOC

AC_CHECK_FUNCS([memset])

 

AC_CONFIG_FILES([Makefile

examples/Makefile

src/Makefile])

AC_OUTPUT

改为:

# -*- Autoconf -*-

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

 

AC_PREREQ([2.69])

AC_INIT(libmessage, 1.0, [email protected])

AC_CONFIG_SRCDIR([src/zk_message.c])

AC_CONFIG_HEADERS([config.h])

 

# Checks for programs.

AC_PROG_CC

AM_INIT_AUTOMAKE

AM_PROG_AR

LT_INIT

AC_CONFIG_MACRO_DIR([m4])

 

# Checks for libraries.

# FIXME: Replace `main' with a function in `-lmessage':

AC_CHECK_LIB([message], [main])

# FIXME: Replace `main' with a function in `-lpthread':

AC_CHECK_LIB([pthread], [main])

 

# Checks for header files.

AC_CHECK_HEADERS([stdlib.h string.h unistd.h])

 

# Checks for typedefs, structures, and compiler characteristics.

 

# Checks for library functions.

AC_FUNC_MALLOC

AC_CHECK_FUNCS([memset])

 

AC_CONFIG_FILES([Makefile

examples/Makefile

src/Makefile])

AC_OUTPUT

5.touch NEWS README AUTHORS ChangeLog

6、 使用libtoolize -f -c、aclocal、autoreconf --install

 

7.创建安装目录 _install

mkdir _install

9生成Makefile

./configure --host=aarch64-himix100-linux --prefix=$(pwd)/_install

10.make;make install

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章