Skip to content

Instantly share code, notes, and snippets.

@hajimehoshi
Last active January 24, 2021 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hajimehoshi/2a5743973c2bbed4d452798513c0a679 to your computer and use it in GitHub Desktop.
Save hajimehoshi/2a5743973c2bbed4d452798513c0a679 to your computer and use it in GitHub Desktop.
Cgo Cross-compile
FROM ubuntu:latest
RUN apt-get update && apt-get install -y \
gcc-10-aarch64-linux-gnu \
gcc-10-multilib \
wget
# Install Go
RUN wget -O go.tar.gz https://dl.google.com/go/go1.15.7.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go.tar.gz && \
rm go.tar.gz
ENV PATH "/usr/local/go/bin:${PATH}"
WORKDIR /work
package main
import "C"
//export Foo
func Foo() C.int {
return 42
}
func main() {
}
docker run --rm --volume $(pwd):/work $(docker build -q .) /bin/bash -c \
"env GOOS=linux GOARCH=arm64 \
CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc-10 \
go build -buildmode=c-archive -o foo.a foo.go"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment