Last active
January 24, 2021 09:13
-
-
Save hajimehoshi/2a5743973c2bbed4d452798513c0a679 to your computer and use it in GitHub Desktop.
Cgo Cross-compile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "C" | |
//export Foo | |
func Foo() C.int { | |
return 42 | |
} | |
func main() { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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