Closed crogre closed 10 years ago
Unfortunately, cgo does not work well with cross-compiling. https://code.google.com/p/go/issues/detail?id=4714
goserial uses cgo (see https://github.com/tarm/goserial/blob/master/serial_posix.go), which is probably why it's not working. Using cgo makes the interface and api easily cross-platform, but unfortunately does not allow cross-compiles.
You have a couple options: 1) you could compile natively on your arm board (might be slow and use most of the ram?) 2) you could use syscalls instead of cgo. That would mean writing a new serial_syscall.go file that had the build flags "linux,!cgo" and implemented the openPort() function in the same way as serial_posix. That actually wouldn't be too bad, and is what I would recommend you do. Please send a patch if you do that! 3) you may be able to hack around to get cgo cross compiling to work if you copy over the right files. Not sure. 4) You could try other serial packages that use syscalls instead of cgo. I know of (but have never used) these ones: github.com/ziutek/serial github.com/knieriem/g/sercom
Thanks for your reply! I think I'll give (2) a shot - I'm new to go and that might teach me a valuable lesson :-)
Support for cross-compiling without cgo (option 2 above) should work as of b1a1181.
I did a golang crosscompilation toolchain build for linux-arm (on a Mac OS X 10.8) following the instructions on http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go (with go version 1.1). And I've confirmed the crosscompilation builds works (simple hello world, webserver etc.)
However, when I try to install goserial I run into problems:
Any pointers to what might be wrong? (for in-platform, "go get github..." works nicely).