下面介紹一下具體過程。
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
搞掂