'_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found while running go test in VS Code after upgrading to mac OS Big Sur

I'm trying to learn select statements in go from learn go with tests. Just before this I upgraded macOS to Big Sur version 11.4. Now I'm trying to run the following tests in VS Code.

package racer
import(
    "time"
    "net/http"
)

//Racer ...
func Racer(a,b string)(winner string){
    startA :=time.Now()
    http.Get(a)
    Aduration:=time.Since(startA)
    startB :=time.Now()
    http.Get(b)
    Bduration:=time.Since(startB)
    if Aduration < Bduration{
        return a
    }
    return b
}

The test is

package racer
import(
    "time"
    "net/http"
)

//Racer ...
func Racer(a,b string)(winner string){
    startA :=time.Now()
    http.Get(a)
    Aduration:=time.Since(startA)
    startB :=time.Now()
    http.Get(b)
    Bduration:=time.Since(startB)
    if Aduration < Bduration{
        return a
    }
    return b
}

This is my go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user_name/Library/Caches/go-build"
GOENV="/Users/user_name/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/user_name/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/user_name/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="/Users/user_name/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-ar"
CC="x86_64-apple-darwin13.4.0-clang"
CXX="x86_64-apple-darwin13.4.0-clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zc/4r25vdyj4cv3ynjx64633ly40000gn/T/go-build3724662099=/tmp/go-build -gno-record-gcc-switches -fno-common"

When I tried to run this test using go test, it returned an error saying runtime/cgo ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libpthread.tbd' for architecture x86_64 clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

After doing some online research, I removed my command line tools using sudo rm -rf /Library/Developer/CommandLineTools, I restarted my system, an pop up appeared asking me to download command line tools again. I installed them. When I'm trying to test the code again using go test, it is returning an error runtime/cgo _cgo_export.c:3:10: fatal error: 'stdlib.h' file not found. I did xcode-select --install but it is already installed. I didn't face any of these issues before the upgrade. May be something changed after the upgrade. Can I please get some help in resolving this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source