# study_golang **Repository Path**: ytxfate/study_golang ## Basic Information - **Project Name**: study_golang - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-07 - **Last Updated**: 2026-07-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # study golang ### 编译 1. CGO_ENABLED=0 amd64 > amd64 ```bash GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -ldflags "-extldflags '-static'" -o "xxx" ``` 2. CGO_ENABLED=0 amd64 > arm64 ```bash GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -a -ldflags "-extldflags '-static'" -o "xxx" ``` 3. CGO_ENABLED=1 amd64 > amd64 ```bash GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -a -ldflags "-extldflags '-static'" -o "xxx" ``` 4. CGO_ENABLED=1 arm64 > arm64 ```bash GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -a -ldflags "-extldflags '-static'" -o "xxx" ``` > `-ldflags "-extldflags '-static'"` 静态链接, 将所有依赖的 C 库(如标准库或第三方库)直接嵌入到生成的可执行文件中,而不是生成动态链接的二进制文件 > 编译尽量使用 `CGO_ENABLED=0` , 如果不可避免且跨架构时则需要到指定架构平台进行编译