unable to set 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:


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

>Solution :

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

go run -race .

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

Is there any way to set environment variables in Visual Studio Code?

Leave a Reply