【Go】跨平台编译
在Window系统编译Linux系统可执行程序脚本,linux_x86.bat
@echo off
REM Building Linux x86_64 Platform
echo Building Linux x86_64 version...
REM Setting platform environment variables
SET CGO_ENABLED=0
set GOOS=linux
set GOARCH=amd64
REM Compiling the program
go build -o main_linux main.go
if %ERRORLEVEL% EQU 0 (
echo.
echo Build successful!
echo Generated: main_linux
echo Target platform: Linux x86_64
) else (
echo.
echo Build failed, please check the error information
)
在Window系统编译可执行文件,windows_x86.bat
@echo off
REM Building Windows x86_64 Platform
echo Building Windows x86_64 version...
REM Setting platform environment variables
SET CGO_ENABLED=0
set GOOS=windows
set GOARCH=amd64
REM Compiling the program
go build -o main_windows.exe main.go
if %ERRORLEVEL% EQU 0 (
echo.
echo Build successful!
echo Generated: main_windows
echo Target platform: Windows x86_64
) else (
echo.
echo Build failed, please check the error information
)

浙公网安备 33010602011771号