无法设置CGO_ENABLED=1。

huangapple go评论84阅读模式
英文:

unable to set CGO_ENABLED=1

问题

所以我正在尝试使用以下命令从Visual Studio Code运行我的代码:

go run -race .

这给我报错:

go: -race需要cgo;通过设置CGO_ENABLED=1来启用cgo

我尝试使用以下命令进行设置,但没有任何反应:

set CGO_ENABLED=1

有人可以告诉我如何将CGO_ENABLED环境变量设置为1吗?因为我无法做到。

英文:

So I am trying to run my code from visual studio code using the command

go run -race .

This is giving me the error:

go: -race requires cgo; enable cgo by setting CGO_ENABLED=1

I tried setting it by using the command but nothing happens:

set CGO_ENABLED=1

Can somebody tell me how to set the CGO_ENABLED env variable to 1 because I am not able to do it

答案1

得分: 1

你可以编写一个批处理脚本 run.bat 来运行你的代码:

set CGO_ENABLED=1
go run -race .

要在Visual Studio Code中完成这个操作,你可以通过启动脚本修改环境变量,参考这个问题:

https://stackoverflow.com/questions/48595446/is-there-any-way-to-set-environment-variables-in-visual-studio-code

英文:

You can write a batch script run.bat to run your code:

set CGO_ENABLED=1
go run -race .

To accomplish this in Visual Studio Code, you can modify the environment variables via a launch script, see this question:

https://stackoverflow.com/questions/48595446/is-there-any-way-to-set-environment-variables-in-visual-studio-code

huangapple
  • 本文由 发表于 2023年7月13日 02:38:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76673557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定