登录
首页 >  Golang >  Go问答

有人可以建议为什么从源代码(1.4)开始构建会因为 GCC 编译错误而失败,即使 CGO_ENABLED=0

来源:stackoverflow

时间:2024-04-28 21:09:34 376浏览 收藏

大家好,今天本人给大家带来文章《有人可以建议为什么从源代码(1.4)开始构建会因为 GCC 编译错误而失败,即使 CGO_ENABLED=0》,文中内容主要涉及到,如果你对Golang方面的知识点感兴趣,那就请各位朋友继续看下去吧~希望能真正帮到你们,谢谢!

问题内容

在 go/src 中找到的文件 make.bat(解压 tar 后)中,甚至在使用 cgo_enabled 检查之前就有一个 gcc 编译命令。这会扰乱引导工具的构建。

出于安全原因,我无法通过 cygwin 或 ming 在 windows 上安装 gcc。然而,编译是针对各种 .c 文件的,这让我不确定下一步该做什么。

我已经修改了源代码和环境变量,特别是 cgo_enabled,这应该是我所需要的。然而,make.bat 具有令人恼火的小 c 编译,这似乎让我感到厌烦。

这是 make.bat 文件和让我失望的编译:

:: CGO_ENABLED: Controls cgo usage during the build. Set it to 1
:: to include all cgo related files, .c and .go file with "cgo"
:: build directive, in the build. Set it to 0 to ignore them.

@echo off

:: Keep environment variables within this script
:: unless invoked with --no-local.
if x%1==x--no-local goto nolocal
if x%2==x--no-local goto nolocal
setlocal
:nolocal

set GOBUILDFAIL=0

if exist make.bat goto ok
echo Must run make.bat from Go src directory.
goto fail 
:ok

:: Clean old generated file that will cause problems in the build.
del /F ".\pkg\runtime\runtime_defs.go" 2>NUL

:: Grab default GOROOT_FINAL and set GOROOT for build.
:: The expression %VAR:\=\\% means to take %VAR%
:: and apply the substitution \ = \\, escaping the
:: backslashes.  Then we wrap that in quotes to create
:: a C string.
cd ..
set GOROOT=%CD%
cd src
if "x%GOROOT_FINAL%"=="x" set GOROOT_FINAL=%GOROOT%
set DEFGOROOT=-DGOROOT_FINAL="\"%GOROOT_FINAL:\=\\%\""

echo # Building C bootstrap tool.
echo cmd/dist/*.c
if not exist ..\bin\tool mkdir ..\bin\tool
:: Windows has no glob expansion, so spell out cmd/dist/*.c.
gcc -O2 -Wall -Werror -o cmd/dist/dist.exe -Icmd/dist %DEFGOROOT% cmd/dist/buf.c cmd/dist/build.c cmd/dist/buildgc.c cmd/dist/buildgo.c cmd/dist/buildruntime.c cmd/dist/main.c cmd/dist/windows.c cmd/dist/arm.c
if errorlevel 1 goto fail
.\cmd\dist\dist env -wp >env.bat
if errorlevel 1 goto fail
call env.bat
del env.bat
echo.

最终结果只是一个标准的 gcc 错误:

构建 c 引导工具。

cmd/dist/*.c

“gcc”不被识别为...


解决方案


Go 1.4 是用 C 编写的,因此需要 C 来编译。 CGO与此完全无关。

Go 1.5 是第一个不需要 C 构建的版本。

本篇关于《有人可以建议为什么从源代码(1.4)开始构建会因为 GCC 编译错误而失败,即使 CGO_ENABLED=0》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>