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

问题描述 投票:0回答:2

我正在尝试从

通过测试学习 go 来学习 
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 }
这是我的环境

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
 但它已经安装了。升级之前我没有遇到任何这些问题。升级后可能会有一些变化。我可以得到一些帮助来解决这个问题吗?

macos go macos-big-sur
2个回答
0
投票
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include /usr/include
    

0
投票
尝试将 SDKROOT 显式设置为系统 SDK:

export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
    
© www.soinside.com 2019 - 2024. All rights reserved.