golang交叉编译
交叉编译需要linux环境
windows
-
安装编译器
apt install gcc-mingw-w64
-
编译指令
windows:
CGO_ENABLED=1 \
GOOS=windows \
GOARCH=amd64 \
CC=x86_64-w64-mingw32-gcc \
go build \
-buildmode=c-shared \
-ldflags \
" -s -w \
-X '${ProjectName}/version.BuildTime=${BUILD_TIME}' \
-X '${ProjectName}/version.Version=${Version}' \
-X '${ProjectName}/version.Author=${BUILD_AUTHOR}' \
-X '${ProjectName}/version.Hash=${BUILD_HASH}' \
" \
-o build/bin/windows/${OutAppName}.dll
ARM64
-
安装编译器
apt install gcc-aarch64-linux-gnu
-
编译指令
linux-arm64:
CGO_ENABLED=1 \
GOOS=linux \
GOARCH=arm64 \
CC=aarch64-linux-gnu-gcc \
go build \
-buildmode=c-shared \
-ldflags \
" -s -w \
-X '${ProjectName}/version.BuildTime=${BUILD_TIME}' \
-X '${ProjectName}/version.Version=${Version}' \
-X '${ProjectName}/version.Author=${BUILD_AUTHOR}' \
-X '${ProjectName}/version.Hash=${BUILD_HASH}' \
" \
-o build/bin/linux/arm64/lib${OutAppName}.so