交叉編譯需要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