下面介绍一下具体过程。
1.在http://www.tcpdump.org下载libpcap-1.0.0.tar.gz和tcpdump-4.0.0.tar.gz两个文件。
2.将这两个文件放在/home下解压。
3.编译,安装libpcap-1.0.0:
(1)进入libpcap目录,打开configure。将下面两端代码注释掉
#if test -z "$with_pcap" && test "$cross_compiling" = yes; then
# { { echo "$as_me:$LINENO: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&5
#echo "$as_me: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&2;}
# { (exit 1); exit 1; }; }
#fi
.......
# if test $ac_cv_linux_vers = unknown ; then
# { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5
#echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;}
# { (exit 1); exit 1; }; }
# fi
运行./configure --host=arm CC=arm-uclibc
(如果不注释掉上面两段代码,可能会出现determine linux version when cross-compiling或
pcap type not determined when cross-compiling导致无法configure)。
运行开始的时候可能会出现个warning说不能用--host,configure的时候会自动识别交叉编译,
但事实上不是这样,还是需要./configure --host=arm-uclibc-linux才会识别用什么交叉编译。
(2)配置之后,会生成Makefile。打开Makefile发现CC=arm-uclibc-linux-gcc,说明交叉编译配置成功。
但还需要把prefix项为prefix=/usr/local/arm/3.4.1/arm-uclibc-linux。然后make,make install。
发现/usr/local/arm/3.4.1/arm-uclibc-linux/include有了3个pcap文件,libpcap编译安装成功。
3.编译,安装tcpdump-4.0.0
(1)进入tcpdump目录,打开configure,将下面一段代码注释掉
# if test $ac_cv_linux_vers = unknown ; then
# { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5
#echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;}
# { (exit 1); exit 1; }; }
# fi
运行./configure --host=arm CC=arm-uclibc
(2)打开生成的Makefile,将INCLS项改为INCLS=-I.-I./../libpcap-1.0.0 -I$(srcdir)/missing -I/usr/local/include,
DEFS项改为DEFS=-DHAVE_CONFIG_H -I./../libpcap-1.0.0 -I/usr/local/include -I$(srcdir)missing -D_U="__attribute__((unused))"。
LDFLAGS=-L/usr/local/lib。然后make,make install。在/usr/local/sbin下有个tcpdump的二进制文件,这个就是交叉编译成功的tcpdump
(3)将这个二进制文件放到tftpboot文件夹,用过tftp将这个文件下载到arm板上,chmod 777 tcpdump将其变为可执行文件。
(4)运行tcpdump,成功!
你可能需要解决一些依赖关系,比如flex,m4,bison等
http://ftp.gnu.org/gnu/m4/
http://ftp.gnu.org/gnu/bison/
http://jaist.dl.sourceforge.net/sourceforge/flex/flex-2.5.35.tar.gz
安装顺序:
m4,flex,bison,libpcap,tcpdump。
最后排错:
(1)
undefined reference to `ip6_print'
然后我尝试使用./configure --disable-ipv6 来消除这个错误,可是不管用。
没办法,只好去源代码里看看了。是print-enc.c 这个文件,打开后找到了这么一段:
case AF_INET6:
ip6_print(p, length);
break;
我直接把ip6_print(p, length);这行给注释了,你不是说未定义的引用么,呵呵。
然后make && make install,一切正常。
(2)
./print-esp.c:75: error: parse error before '*' token
./print-esp.c:80: error: parse error before '}' token
可能是某些编译器不支持“复数”;解决:
#make distclean
#./configure --host=arm CC=arm-uclibc --without-crypto
#make
#make install
搞掂