gpt4 book ai didi

macos - 当构建参数包含`-gcflags“all = -N -l”并在MacOS中导入net/http时,构建失败

转载 作者:行者123 更新时间:2023-12-01 22:24:45 27 4
gpt4 key购买 nike

当我尝试调试时,go build参数包含-gcflags "all=-N -l",并且我导入net/http,那么构建将失败。
我尝试使用brew重新安装golang,但无法正常工作。
并尝试在卸载后使用offical installation,不起作用。
而且我尝试sudo mv /Library/Developer/CommandLineTools CommandLineTools.old && xcode-select --install,不起作用。
在JimB的建议下,我尝试了go env -w CGO_ENABLED=0,以便可以正确构建。
有什么建议么?
构建失败消息:

# crypto/x509
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: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 main
import "os"
func main() {
println(os.Args)
}
> go build main.go # success
> go build -gcflags "all=-N -l" main.go # success

--------------------------------------

package main
import "net/http"
func main() {
println(http.DefaultClient)
}
> go build main.go # success
> go build -gcflags "all=-N -l" main.go # fail <-----------


MacOS版本:10.13.6
Xcode版本:10.0
转到1.14版

> go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/XXX/Library/Caches/go-build"
GOENV="/Users/XXX/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/XXX/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build994818786=/tmp/go-build -gno-record-gcc-switches -fno-common"
我发现一些类似的问题: Go: build error when compiling unit tests (I'm trying to mock influxdb types)
但是我没有使用相对进口

最佳答案

  • go env -w CGO_ENABLED=0可以暂时解决此问题。
  • 升级MacOS和XCode之后,此问题不再发生。

  • 现在我的版本:

    MacOS 10.15.3
    XCode 11.3.1(11C504)

    关于macos - 当构建参数包含`-gcflags“all = -N -l”并在MacOS中导入net/http时,构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60754062/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com