libsub_la_SOURCES=sub.c 在hello下也要编写Makefile.am,内容如下: UTOMAKE_OPTIONS=foreign SUBDIRS=add sub bin_PROGRAMS=main main_SOURCES=main.c main_LDADD=add/libadd.la sub/libsub.la 6> 写好了Makefile.am,运行automake -a 7> 然后执行 ./configure 8> 最后make [root@localhost root]# cd hello [root@localhost hello]# ls add main.c sub [root@localhost hello]#autoscan [root@localhost hello]# ls add autoscan.log configure.scan main.c sub [root@localhost hello]# vim configure.in # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) AM_INIT_AUTOMAKE(main,1.0) AC_CONFIG_SRCDIR([main.c]) AC_CONFIG_HEADER([config.h]) # Checks for programs. AC_PROG_CC # Checks for libraries. AC_PROG_LIBTOOL # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. AC_OUTPUT(Makefile add/Makefile sub/Makefile)
[root@localhost hello]# libtoolize You should add the contents of `/usr/share/aclocal/libtool.m4' to `aclocal.m4'. [root@localhost hello]# ls add config.guess configure.in ltmain.sh sub autoscan.log config.sub configure.scan main.c [root@localhost hello]# aclocal [root@localhost hello]# autoconf [root@localhost hello]# autoheader [root@localhost hello]# ls aclocal.m4 autoscan.log config.sub configure.scan sub add config.guess configure ltmain.sh autom4te.cache config.h.in configure.in main.c //接下来编写3个Makefile.am,这个过程我就不细说啦。 [root@localhost hello]#ls aclocal.m4 autoscan.log config.sub configure.scan Makefile.am add config.guess configure ltmain.sh sub autom4te.cache config.h.in configure.in main.c [root@localhost hello]# ls ./add add.c Makefile.am [root@localhost hello]# ls ./sub Makefile.am sub.c [root@localhost hello]# automake -a configure.in:8: `automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER' configure.in: installing `./install-sh' configure.in: installing `./mkinstalldirs' configure.in: installing `./missing' Makefile.am: installing `./INSTALL' Makefile.am: required file `./NEWS' not found Makefile.am: required file `./README' not found Makefile.am: installing `./COPYING' Makefile.am: required file `./AUTHORS' not found Makefile.am: required file `./ChangeLog' not found Makefile.am: installing `./depcomp' [root@localhost hello]# ls aclocal.m4 config.guess configure.in INSTALL Makefile.am sub add config.h.in configure.scan install-sh Makefile.in autom4te.cache config.sub COPYING ltmain.sh missing autoscan.log configure depcomp main.c mkinstalldirs //又多了几个东东 [root@localhost hello]# ./configure //这个过程比较长 checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for gcc... gcc checking for C compiler default output... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... 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 ANSI C... none needed checking for style of include used by make... GNU checking dependency style of gcc... gcc3 checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking for ld used by GCC... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for /usr/bin/ld option to reload object files... -r checking for BSD-compatible nm... /usr/bin/nm -B checking for a sed that does not truncate output... /bin/sed checking whether ln -s works... yes checking how to recognise dependent libraries... pass_all checking command to parse /usr/bin/nm -B output... ok checking how to run the C preprocessor... gcc -E checking for egrep... grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking dlfcn.h usability... yes checking dlfcn.h presence... yes checking for dlfcn.h... yes checking for ranlib... ranlib checking for strip... strip checking for objdir... .libs checking for gcc option to produce PIC... -fPIC checking if gcc PIC flag -fPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.lo... yes checking if gcc supports -fno-rtti -fno-exceptions... yes checking whether the linker (/usr/bin/ld) supports shared libraries... yes checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking dynamic linker characteristics... GNU/Linux ld.so checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking whether -lc should be explicitly linked in... no creating libtool configure: creating ./config.status config.status: creating Makefile //看到这三个Makefile了没有,呵呵,它已经建好了 config.status: creating add/Makefile config.status: creating sub/Makefile config.status: creating config.h config.status: executing depfiles commands [root@localhost hello]# make //这个也有点花时间 cd . && /bin/sh ./config.status config.h config.status: creating config.h config.status: config.h is unchanged make all-recursive make[1]: Entering directory `/root/hello' Making all in add make[2]: Entering directory `/root/hello/add' source='add.c' object='add.lo' libtool=yes \ depfile='.deps/add.Plo' tmpdepfile='.deps/add.TPlo' \ depmode=gcc3 /bin/sh ../depcomp \ /bin/sh ../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c -o add.lo `test -f 'add.c' || echo './'`add.c rm -f .libs/add.lo gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c add.c -MT add.lo -MD -MP -MF .deps/add.TPlo -fPIC -DPIC -o .libs/add.lo gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c add.c -MT add.lo -MD -MP -MF .deps/add.TPlo -o add.o >/dev/null 2>&1 mv -f .libs/add.lo add.lo /bin/sh ../libtool --mode=link gcc -g -O2 -o libadd.la -rpath /usr/local/lib add.lo rm -fr .libs/libadd.la .libs/libadd.* .libs/libadd.* gcc -shared add.lo -Wl,-soname -Wl,libadd.so.0 -o .libs/libadd.so.0.0.0 (cd .libs && rm -f libadd.so.0 && ln -s libadd.so.0.0.0 libadd.so.0) (cd .libs && rm -f libadd.so && ln -s libadd.so.0.0.0 libadd.so) ar cru .libs/libadd.a add.o ranlib .libs/libadd.a creating libadd.la (cd .libs && rm -f libadd.la && ln -s ../libadd.la libadd.la) make[2]: Leaving directory `/root/hello/add' Making all in sub make[2]: Entering directory `/root/hello/sub' source='sub.c' object='sub.lo' libtool=yes \ depfile='.deps/sub.Plo' tmpdepfile='.deps/sub.TPlo' \ depmode=gcc3 /bin/sh ../depcomp \ /bin/sh ../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c -o sub.lo `test -f 'sub.c' || echo './'`sub.c rm -f .libs/sub.lo gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c sub.c -MT sub.lo -MD -MP -MF .deps/sub.TPlo -fPIC -DPIC -o .libs/sub.lo gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c sub.c -MT sub.lo -MD -MP -MF .deps/sub.TPlo -o sub.o >/dev/null 2>&1 mv -f .libs/sub.lo sub.lo /bin/sh ../libtool --mode=link gcc -g -O2 -o libsub.la -rpath /usr/local/lib sub.lo rm -fr .libs/libsub.la .libs/libsub.* .libs/libsub.* gcc -shared sub.lo -Wl,-soname -Wl,libsub.so.0 -o .libs/libsub.so.0.0.0 (cd .libs && rm -f libsub.so.0 && ln -s libsub.so.0.0.0 libsub.so.0) (cd .libs && rm -f libsub.so && ln -s libsub.so.0.0.0 libsub.so) ar cru .libs/libsub.a sub.o ranlib .libs/libsub.a creating libsub.la (cd .libs && rm -f libsub.la && ln -s ../libsub.la libsub.la) make[2]: Leaving directory `/root/hello/sub' make[2]: Entering directory `/root/hello' source='main.c' object='main.o' libtool=no \ depfile='.deps/main.Po' tmpdepfile='.deps/main.TPo' \ depmode=gcc3 /bin/sh ./depcomp \ gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c `test -f 'main.c' || echo './'`main.c /bin/sh ./libtool --mode=link gcc -g -O2 -o main main.o add/libadd.la sub/libsub.la mkdir .libs gcc -g -O2 -o .libs/main main.o add/.libs/libadd.so sub/.libs/libsub.so -Wl,--rpath -Wl,/usr/local/lib creating main //看到它了没有,它是可执行的文件,运行它就可以看到结果拉 cd . && /bin/sh ./config.status config.h config.status: creating config.h config.status: config.h is unchanged make[2]: Leaving directory `/root/hello' make[1]: Leaving directory `/root/hello' [root@localhost hello]# ls aclocal.m4 config.h.in configure.scan ltmain.sh Makefile.in add config.log COPYING main missing autom4te.cache config.status depcomp main.c mkinstalldirs autoscan.log config.sub INSTALL main.o sub config.guess configure install-sh Makefile config.h configure.in libtool Makefile.am [root@localhost hello]# ./main sub_x: 6 sub_y: 5 add_x=sub(6, 5)= 1 add_y: 4 5[root@localhost hello]#
文章评论(0条评论)
登录后参与讨论