當我嘗試調試時,go build參數包含-gcflags "all=-N -l",然后我導入net/http,然后構建將失敗。我嘗試使用 brew 重新安裝 golang,但不起作用。并在卸載后嘗試使用官方安裝,不工作。我正在嘗試sudo mv /Library/Developer/CommandLineTools CommandLineTools.old && xcode-select --install,不工作。在 JimB 的建議下,我嘗試go env -w CGO_ENABLED=0了 ,以便我可以正確構建。有什么建議么?構建失敗消息:# crypto/x509In file included from /usr/local/Cellar/go/1.14/libexec/src/crypto/x509/root_cgo_darwin.go:17:In file included from /System/Library/Frameworks/Security.framework/Headers/Security.h:31:/System/Library/Frameworks/Security.framework/Headers/SecItem.h:452:49: error: expected ',' API_AVAILABLE(macos(10.7), ios(NA), bridgeos(NA)); ^ ...... ^In file included from /usr/local/Cellar/go/1.14/libexec/src/crypto/x509/root_cgo_darwin.go:17:In file included from /System/Library/Frameworks/Security.framework/Headers/Security.h:35:/System/Library/Frameworks/Security.framework/Headers/SecImportExport.h:317:55: error: expected ',' API_AVAILABLE(macos(10.7), ios(NA), bridgeos(NA)); ^ ....../System/Library/Frameworks/Security.framework/Headers/SecImportExport.h:656:49: error: expected ',' API_AVAILABLE(macos(10.7), ios(NA), bridgeos(NA)); ^ ......27 errors generated.package mainimport "os"func main() { println(os.Args)}> go build main.go # success> go build -gcflags "all=-N -l" main.go # success--------------------------------------package mainimport "net/http"func main() { println(http.DefaultClient)}> go build main.go # success> go build -gcflags "all=-N -l" main.go # fail <-----------
1 回答

肥皂起泡泡
TA貢獻1829條經驗 獲得超6個贊
go env -w CGO_ENABLED=0
可以暫時解決這個問題。升級 MacOS 和 XCode 后,此問題不再出現。
現在我的版本:
macOS 10.15.3
XCode 11.3.1(11C504)
- 1 回答
- 0 關注
- 269 瀏覽
添加回答
舉報
0/150
提交
取消