【Go】跨平台编译

参考文章:https://www.topgoer.com/%E5%85%B6%E4%BB%96/%E8%B7%A8%E5%B9%B3%E5%8F%B0%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91.html

在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
)

 

posted @ 2026-04-01 21:14  谷粒-笔记  阅读(1)  评论(0)    收藏  举报