gpt4 book ai didi

macos - MacOS Catalina 升级后 Go 程序无法运行

转载 作者:行者123 更新时间:2023-12-05 06:11:05 24 4
gpt4 key购买 nike

这可能是一个奇怪的问题,但在 MacOS Catalina 升级后,一些用 Go 编写的程序将无法在我的 MacBook Pro 上运行。

然而,一个基本的“Hello World”程序运行,但随后我使用 net/http 包编写程序,我收到以下错误:

Note: The programs are correct, they run fine inside a Docker container

输出(IntelliJ):


# runtime/cgo
In file included from gcc_darwin_amd64.c:6:
/usr/local/include/pthread.h:331:6: error: macro expansion producing 'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/usr/local/include/pthread.h:200:2: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
/usr/local/include/pthread.h:331:6: error: macro expansion producing 'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/usr/local/include/pthread.h:200:34: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
/usr/local/include/pthread.h:540:6: error: macro expansion producing 'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/usr/local/include/pthread.h:200:2: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'
/usr/local/include/pthread.h:540:6: error: macro expansion producing 'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/usr/local/include/pthread.h:200:34: note: expanded from macro '_PTHREAD_SWIFT_IMPORTER_NULLABILITY_COMPAT'

我已经尝试过的事情:

  1. 重新安装 go
  2. 重新安装xcode
  3. 检查 GOPATHGOROOT 是否设置正确

用过的:

MacOS version - Catalina 10.15.6
Go version - go1.15.2 darwin/amd64

最佳答案

在终端窗口中键入 xcode-select -print-path 并检查您的安装目录。在我的例子中,输出是:/Applications/Xcode.app/Contents/Developer

如果情况相同,则在您的终端上使用以下命令可以解决问题:

sudo xcode-select --switch /Library/Developer/CommandLineTools

另一种选择是使用此 issue 中提到的 CGO_CPPFLAGS , 但它会在 session 中工作:

export CGO_CPPFLAGS="-Wno-error -Wno-nullability-completeness -Wno-expansion-to-defined -Wno-builtin-requires-header"

关于macos - MacOS Catalina 升级后 Go 程序无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64149070/

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