This is a creation in Article, where the information may have evolved or changed.
Golang Pass the very ox X, but can not cross-compile, for me a little use is not, there is an open source project is written with Golang, if not in arm, then I can only "translate" into C, and then integrated into my product, but I do not have this time.
Fortunately, cross-compilation finally succeeded.
1. Preparatory work
1.1 Golang environment and arm cross-compiler tool
You can refer to the "Golang installation Codex" this article.
1.2 gcc Cross Compiler
On the basis of 1.1, it is possible to compile the binary of pure Golang written on arm, but there is an unresolved problem: Golang and C jointly developed module, compile times wrong:
Can ' t load package:no buildable Go source files in/...
The problem is that, when CGO is turned off, the Golang compiler automatically "ignores" the source file with the word "import" C "". To resolve this issue, you need to open CGO support, such as the compile-time command instead:
Goarch=arm cgo_enabled=1 Go Build hello.go
However, this is not enough and requires the installation of the arm platform compiler, such as Gcc-4.7-arm-linux-gnueabi (the version number to match the version number of the target platform ), And the support of Gcc-4.7-multilib-arm-linux-gnueabi. You will also need to re-/USR/BIN/GCC LN to arm's cross-compiler.
After the completion of the above work, import "C" will be no problem.
1.3 Third-party libraries
The main purpose of using the import "C" is to use third-party open source libraries, Golang find third-party libraries using pkg-config, first of all to ensure that pkg-config normal work, in addition, to ensure that third-party libraries, and third-party libraries of the dependent libraries, are arm version, To link successfully. Link the successful Golang program, you can happily run on the arm board.
Golang's initial adventure to some end, from the next code to complete this blog, time spent more than a day, my program is also happy to run on the board.