4

I am using the Revel framework to make a web application. I am cross compiling it for ARM with the command GOOS=linux GOARCH=arm revel package mitm

This works fine, however I have just included the library github.com/google/gopacket

and now the cross compiled build fails (it runs fine on OSX that I am developing on).

I get:

ERROR 2015/07/27 09:01:30 build.go:101: # mitm/app/controllers go/src/webserver/app/controllers/ArpScan.go:88: undefined: pcap.OpenLive go/src/webserver/app/controllers/ArpScan.go:88: undefined: pcap.BlockForever go/src/webserver/app/controllers/ArpScan.go:114: undefined: pcap.Handle go/src/webserver/app/controllers/ArpScan.go:145: undefined: pcap.Handle

pcap is a library imported from gopacket:

import "github.com/google/gopacket/pcap"

My question is how do I get it to cross compile this library aswell?

I ran Dave Cheney's go-crosscompile-build-all (link) but that just builds the standard library.

Alex Netkachov
  • 13,172
  • 6
  • 53
  • 85
amlwwalker
  • 3,161
  • 4
  • 26
  • 47
  • That package uses cgo, do you have a C compiler for the target architecture? – Ainar-G Jul 27 '15 at 10:25
  • Ahh ok, so I need a cross platform C compiler on my mac to be able to compile that library for ARM? Do you have a link to some tutorial? how do I check if I have a C compiler for that architecture? I've not knowingly installed one. What are the steps once I do have one? – amlwwalker Jul 27 '15 at 10:52
  • I don't have an OS X machine, so I can't really help with that. Look for cross-compilers in the brew repos, and if there aren't any, look up the instructions to build them. – Ainar-G Jul 27 '15 at 10:57
  • 1
    Try this: https://github.com/tpoechtrager/osxcross (and then realize what a huge pain cross-compiling C across OS' & architectures is and just boot a small Ubuntu VM with build-essential & the Go toolchain installed via https://github.com/travis-ci/gimme) – elithrar Jul 27 '15 at 11:27
  • So I have had minor improvements... I pulled the latest go (1.4.2 src code). I ran `bash all.bash` and that seemed successful. When I run `C=arm-linux-gnueabihf-gcc GOOS=linux GOARCH=arm revel package mitm` I get the error: "go build runtime: linux/arm must be bootstrapped using make.bash" I then run `GOOS=linux GOARCH=arm ./make.bash --no-clean` which is successful, however that doesnt allow revel to build successfully – amlwwalker Jul 27 '15 at 11:44
  • You can try getting go1.5beta2 where cross-compiling is done [much easier](https://medium.com/@rakyll/go-1-5-cross-compilation-488092ba44ec). Go 1.5 itself should be out next month. – Ainar-G Jul 27 '15 at 14:37
  • You may be interested in this post that address the problems of hidden Cgo in the standard library as well as a potential solution (gonative). https://inconshreveable.com/04-30-2014/cross-compiling-golang-programs-with-native-libraries/ – golliher Aug 16 '15 at 11:59

1 Answers1

0

Try goxc. It requires the go source and the go toolchain but works well.

Brandon S
  • 1
  • 2