Compile to arm cpu error
dylanlyu opened this issue · 8 comments
C source files not allowed when not using cgo or SWIG: sqlite3-binding.c
i try export CGO_ENABLED=1 but
runtime/cgo
clang: error: argument unused during compilation: '-mno-thumb'
What ideas can be compile successfully???
👍 on OSX (go version go1.5.2 darwin/amd64
) building for Linux
$ CGO_ENABLED=1 GOOS=linux go build -v main.go
runtime
errors
sync/atomic
math
unicode/utf8
sort
unicode
sync
encoding
runtime/cgo
io
syscall
# runtime/cgo
ld: unknown option: --build-id=none
clang: error: linker command failed with exit code 1 (use -v to see invocation)
internal/singleflight
container/list
Hi.i got this problem too.
Did you fix this problem finally?How?
you compiler have --build-id
flag?
CC=arm-none-linux-gnueabi-gcc
Finally, Use this flag to setup you own compiler, not use Clang.
go-sqlite3 doesn't require --build-id
flag but seems go require it.
In case someone else stumbles on this as I did here is the complete info:
- to cross compile you need the cross compiler. I am targeting hard float so mine is arm-linux-gnueabihf-gcc/arm-linux-gnueabihf-g++ . Get it installed - for linux there are official packages, for mac search around there are plenty of resources on how to get/install the gcc toolchain targeting arm
- add the crosscompiler toolchain to the path
- to build your go program you need to use the above compiler. Just run:
env CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ \
CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 \
go build -v main.go
Chipping in, for those targeting the arm64 arch out of linux distro. Here are the commands:
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
env CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -v -o arm64
FWIW I have a script that compiles rqlite for a bunch of CPU architectures here: https://github.com/rqlite/rqlite/blob/master/scripts/package.sh
These are the needed cross-compilers for Linux:
https://github.com/rqlite/rqlite/blob/master/.circleci/images/circleci-primary/Dockerfile