_cgo_export.c:3:10: 致命错误:升级到 mac OS Big Sur 后在 VS Code 中运行 go test 时找不到“stdlib.h”文件

时间:2021-06-11 07:53:52

标签: macos go macos-big-sur

我正在尝试从 learn go with tests 中学习 select 语句。就在此之前,我将 macOS 升级到 Big Sur 11.4 版。现在我正在尝试在 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
}

测试是

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
}

这是我的 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"

当我尝试使用 go test 运行此测试时,它返回错误消息 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)

在做了一些在线研究之后,我使用 sudo rm -rf /Library/Developer/CommandLineTools 删除了我的命令行工具,我重新启动了我的系统,出现了一个弹出窗口,要求我再次下载命令行工具。我安装了它们。当我尝试使用 go test 再次测试代码时,它返回错误 runtime/cgo _cgo_export.c:3:10: fatal error: 'stdlib.h' file not found。我做了 xcode-select --install 但它已经安装了。在升级之前,我没有遇到任何这些问题。升级后可能会发生一些变化。我能帮我解决这个问题吗?

0 个答案:

没有答案