1. 首先建立一个动态库
void hello()
{
printf("in hello\n");
}
gcc -fPIC -c hhh.c -o libhhh.o
gcc -shared -W1 -o libhhh.so libhhh.o -lc
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
现在就建立了一个动态库了.
接下来使用刚刚建立的这个动态库.
2. 使用autotools将该动态库加入到自己的工程中去
#include<stdio.h>
int main()
{
printf("main\n");
hello();
return 0;
}
bin_PROGRAMS=test
test_SOURCES=src/test.c
test_LDADD=/usr/local/test/libhhh.so
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(test,1.1.1,[chinatan])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/test.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
AC_CHECK_LIB([hhh], [main])
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT([Makefile])
mv configure.scan configure.in
touch NEWS README AUTHORS ChangeLog
此时就可以使用./configure了.
./test 执行就可看到效果.
然后再make dist打包..