猿问

构建参数包含 `-gcflags"all=-N -l"` 并在 MacOS 中导入 net/http

当我尝试调试时,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/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       <-----------


慕哥9229398
浏览 324回答 1
1回答

肥皂起泡泡

go env -w CGO_ENABLED=0可以暂时解决这个问题。升级 MacOS 和 XCode 后,此问题不再出现。现在我的版本:macOS 10.15.3XCode 11.3.1(11C504)
随时随地看视频慕课网APP

相关分类

Go
我要回答