Open amlwwalker opened 9 years ago
I am having the same issue. Anyone has a workaround or solution?
Nvm, Figured out the solution.
Any chance you could post solution?
On Tue, Dec 1, 2015 at 8:14 PM, cnsgcu notifications@github.com wrote:
Nvm, Figured out the solution.
— Reply to this email directly or view it on GitHub https://github.com/google/gopacket/issues/100#issuecomment-161166672.
Download and extract android ndk. I have it under ~/Android/Ndk
Compile libpcap - NOTE: May need to install flex, and yacc, bison
Use the following script to build libpcap - NOTE: Need to change prebuilt/linux-x86 to prebuilt/linux-x86_64, LIBPCAP_DIR, and NDK_ROOT accordingly
LIBPCAP_DIR=libpcap # libpcap NDK_ROOT=~/Android/Ndk # Path to the Android NDK root
openlib() {
if [ ! -d "$2" ]; then
echo "$1 not found.\nPlace it at pwd
/$2";
exit
fi
cd $2
make clean; make distclean
}
checkerror() { if [ "$?" -ne 0 ]; then echo "Error building $1. See log above."; exit fi }
export PATH=$PATH:$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin export PATH=$PATH:$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/include
openlib "libpcap" $LIBPCAP_DIR ./configure \ --host=arm-linux-androideabi \ --with-pcap=linux \ CC=arm-linux-androideabi-gcc \ LD=arm-linux-androideabi-ld \ CFLAGS="--sysroot=$NDK_ROOT/platforms/android-21/arch-arm/" \ LDFLAGS="-L$NDK_ROOT/platforms/android-21/arch-arm/usr/lib/" checkerror "libpcap" make checkerror "libpcap" cd -
Build your app and gopacket - NOTE: Need to change ndk directory accordingly
I am currently busy with coming exams and can not write a general solution. Just write down what I did. Give it a try and let me know if it works.
I was able to cross compile a gopacket Go program for the Pi Zero using the official toolchain that they provide @
git clone git://github.com/raspberrypi/tools.git
Then I cross compiled libpcap-1.7.4 using the toolchain:
./configure --host=arm-linux-gnueabihf --prefix=$PATH_TO_SYSROOT --with-pcap=linux && make && make install
Then I used the flags from step #4 of @cnsgcu's post above, substituting the appropriate values into CGO_CFLAGS, CGO_LDFLAGS, CC, LD, GOOS, and GOARM to match my toolchain and target.
Copied the libpcap.so* files to the Pi Zero's /usr/lib folder and copied my cross compiled Go program and it works as expected.
I have same problem,
GOOS=linux GOARCH=arm go build -o bin/pcapdump-arm src/vendor/github.com/google/gopacket/examples/pcapdump/main.go
# command-line-arguments
src/vendor/github.com/google/gopacket/examples/pcapdump/main.go:31: undefined: pcap.Handle
src/vendor/github.com/google/gopacket/examples/pcapdump/main.go:34: undefined: pcap.OpenOffline
src/vendor/github.com/google/gopacket/examples/pcapdump/main.go:41: undefined: pcap.NewInactiveHandle
src/vendor/github.com/google/gopacket/examples/pcapdump/main.go:54: undefined: pcap.TimestampSourceFromString
How can I fix it?
It's actually quite easy to cross compile this library for ARM (requires gcc-arm-linux-gnueabi
, byacc
and flex
packages).
Step 1: download and cross compile libpcap-1.8.1
(adjust PCAPV to use a different libpcap version):
cd /tmp
export PCAPV=1.8.1
wget http://www.tcpdump.org/release/libpcap-$PCAPV.tar.gz
tar xvf libpcap-$PCAPV.tar.gz
cd libpcap-$PCAPV
export CC=arm-linux-gnueabi-gcc
./configure --host=arm-linux --with-pcap=linux
make
Step 2: now cross compile your tool:
cd $GOPATH/src/github.com/your-user/your-tool
env CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm CGO_LDFLAGS="-L/tmp/libpcap-$PCAPV" go build .
You are welcome.
If you're cross compiling for Android using the NDK this could come in handy: https://github.com/google/gopacket/pull/421
Any where I can find instructions on how to successfully cross compile this library for ARM? I've followed Dave Cheney's instructions but that just compiles the standard library for ARM, not depenencies. Its a cgo issue I think