Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1741832
  • 博文数量: 782
  • 博客积分: 2455
  • 博客等级: 大尉
  • 技术积分: 4140
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-06 21:37
个人简介

Linux ,c/c++, web,前端,php,js

文章分类

全部博文(782)

文章存档

2015年(8)

2014年(28)

2013年(110)

2012年(307)

2011年(329)

分类: LINUX

2012-02-20 17:46:05

1,源文件udp.c 
2,需要连接的动态库为pcap.soXXXX
3,生成的可执行文件myudp
一,建立工作目录
[root@localhost makeso]# pwd
/root/devel/makeso
[root@localhost makeso]# tree 
.
└── udp.c
二,autoscan
[root@localhost makeso]# autoscan
[root@localhost makeso]# ls
autoscan.log  configure.scan  udp.c
[root@localhost makeso]# mv configure.scan configure.in
三,修改configure.in
[root@localhost makeso]# vim configure.in 

  1 #                                               -*- Autoconf -*-
  2 # Process this file with autoconf to produce a configure script.
  3 
  4 AC_PREREQ([2.66])
  5 AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
  6 AC_CONFIG_SRCDIR([udp.c])
  7 AC_CONFIG_HEADERS([config.h])
  8 
  9 # Checks for programs.
 10 AC_PROG_CC
 11 
 12 # Checks for libraries.
 13 
 14 # Checks for header files.
 15 AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/ioctl.h sys/soc
    ket.h unistd.h])
 16 
 17 # Checks for typedefs, structures, and compiler characteristics.
 18 
 19 # Checks for library functions.
 20 AC_CHECK_FUNCS([socket])
 21 
 22 AC_OUTPUT
修改之后
  1 #                                               -*- Autoconf -*-
  2 # Process this file with autoconf to produce a configure script.
  3 
  4 AC_PREREQ([2.66])
  5 AC_INIT(udp.c)
  6 AM_INIT_AUTOMAKE(myudp,1.0)
  7 AC_CONFIG_SRCDIR([udp.c])
  8 #AC_CONFIG_HEADERS([config.h])
  9 
 10 # Checks for programs.
 11 AC_PROG_CC
 12 
 13 # Checks for libraries.
 14 AC_CHECK_LIB([pcap], [main])
 15 
 16 # Checks for header files.
 17 AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/ioctl.h sys/soc
    ket.h unistd.h])
 18 
 19 # Checks for typedefs, structures, and compiler characteristics.
 20 
 21 # Checks for library functions.
 22 AC_CHECK_FUNCS([socket])
 23 
 24 AC_OUTPUT(Makefile)
四,生成configure
[root@localhost makeso]# aclocal
[root@localhost makeso]# autoconf
[root@localhost makeso]# ls
aclocal.m4  autom4te.cache  autoscan.log  configure  configure.in  udp.c
五,编辑Makefile.am
[root@localhost makeso]# vim Makefile.am
  1 AUTOMAKE_OPTIONS= foreign
  2 bin_PROGRAMS= myudp
  3 myudp_SOURCES= udp.c
六,执行 Automake --add-missing ,Automake 会根据Makefile.am 文件产生一些文件,包含最重要的Makefile.in
[root@localhost makeso]# automake --add-missing
configure.in:6: installing `./install-sh'
configure.in:6: installing `./missing'
Makefile.am: installing `./depcomp'
至此,Makefile已经制作完毕,看下效果
[root@localhost makeso]# tree
.
├── aclocal.m4
├── autom4te.cache
│   ├── output.0
│   ├── output.1
│   ├── output.2
│   ├── requests
│   ├── traces.0
│   ├── traces.1
│   └── traces.2
├── autoscan.log
├── configure
├── configure.in
├── depcomp -> /usr/share/automake-1.11/depcomp
├── install-sh -> /usr/share/automake-1.11/install-sh
├── Makefile.am
├── Makefile.in
├── missing -> /usr/share/automake-1.11/missing
└── udp.c

1 directory, 17 files
[root@localhost makeso]# ./configure 
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
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 ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for main in -lpcap... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
……………………………………
……………………
[root@localhost makeso]# make
gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"myudp\" -DVERSION=\"1.0\" -DHAVE_LIBPCAP=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_ARPA_INET_H=1 -DHAVE_FCNTL_H=1 -DHAVE_NETDB_H=1 -DHAVE_NETINET_IN_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_SYS_SOCKET_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SOCKET=1 -I.     -g -O2 -MT udp.o -MD -MP -MF .deps/udp.Tpo -c -o udp.o udp.c
mv -f .deps/udp.Tpo .deps/udp.Po
gcc  -g -O2   -o myudp udp.o  -lpcap 
阅读(2770) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~