有人可以建议为什么从源(1.4)进行Go构建会由于GCC编译错误而失败,即使CGO_ENABLED = 0

In the file make.bat found in go/src (after unzipping tar), there is a gcc compile command even before a check for CGO_ENABLED ever is used. This messes up the bootstrap tool build.

For security reasons I cannot install GCC on Windows via cygwin or ming. However, the compiles are for various .c files which makes me unsure about what to do next.

I've tinkered about with the source code and the environment variables, especially CGO_ENABLED, which should have been all I needed. However, the make.bat haas that irritating little c compile that seems to be throwing me off.

This is the make.bat file and the compile that's throwing me off:

:: 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 ".\pkguntimeuntime_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.

The final result is just a standard gcc error :

Building C bootstrap tool.

cmd/dist/*.c

"gcc" is not recognized as...

dqnqpqv3841
dqnqpqv3841 另外,为什么要从源代码构建而不是下载预编译的版本?
11 个月之前 回复
doubaomao9304
doubaomao9304 为什么要使用Go1.4?那是7岁。如果需要考虑安全性,则绝对应该使用现代版本。
11 个月之前 回复
douwojiao5919
douwojiao5919 对于Go1.4,您需要安装并提供功能齐全的C编译器:Go1.5用C编写。
11 个月之前 回复
dongxuying7583
dongxuying7583 CGO与构建Go无关。Go1.4取决于要构建的C。Go1.5是第一个不需要C的版本。
11 个月之前 回复

1个回答



Go 1.4用C编写,因此需要C进行编译。 CGO与此完全无关。</ p>

转到1.5 </ a>是第一个不需要构建C的版本。</ p>
</ div>

展开原文

原文

Go 1.4 is written in C, and therefore needs C to be compiled. CGO is completely unrelated to this.

Go 1.5 was the first version not to require C to be built.

donglao6169
donglao6169 但这确实需要构建Go。 如果您既没有安装Go也没有安装GCC,则无法从源代码进行构建。
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐