在运行go run -race main.go的时候,出现了以下错误:
如果报错事CGO_ENABLED=0那么直接使用这个命令就好:
go env -w CGO_ENABLED=1
如果报了这个错误: win10 go run报错cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%
解决方法如下:
安装mingw,链接:mingw安装地址
解压安装之后,复制安装目录下的bin文件到【此电脑-->属性-->高级系统设置-->环境变量】
goland下的补充配置
在上面安装之后,可以win+R测试一下是否有效,输入gcc,如果出来的不是无法识别该命令就说明该bin是配置成功的,可以识别该命令。
但是此时在goland下运行go run -race main.go还是失败的。原因是只是该window的系统path变了,需要在goland的powershell或者command prompt里面继续配置。
Window PowerShell
$env:PATH += ";E:\\mingw\\bin" #加入path
echo $env:PATH #查看是否添加成功
Command Prompt
set PATH=%PATH%;E:\\mingw\\bin #加入path
echo %PATH%. #查看是否添加成功