mattshma/bigdata

macOS10.15 'stdlib.h' file not found

mattshma opened this issue · 0 comments

执行 kubebuilder init 时,报错如下:

go get sigs.k8s.io/controller-runtime@v0.4.0
go mod tidy
Running make...
make
/Users/xxx/bin/controller-gen object:headerFile=./hack/boilerplate.go.txt paths="./..."
Error: go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags ignore_autogenerated -- ./...]: exit status 2: # runtime/cgo
_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found

查看了下 stdlib.h 文件位置,执行 export CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include,再次执行 kubebuilder init,报错如下:

go get sigs.k8s.io/controller-runtime@v0.4.0
go mod tidy
Running make...
make
/Users/xxxx/bin/controller-gen object:headerFile=./hack/boilerplate.go.txt paths="./..."
Error: go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags ignore_autogenerated -- ./...]: exit status 2: # runtime/cgo
In file included from _cgo_export.c:3:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:134:25: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:134:25: note: insert '_Nullable' if the pointer may be null
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:134:25: note: insert '_Nonnull' if the pointer should never be null
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:135:22: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]

执行 export CGO_CPPFLAGS="-Wno-error -Wno-nullability-completeness -Wno-expansion-to-defined" 后,再次执行 kubebuilder init,报错如下:

go get sigs.k8s.io/controller-runtime@v0.4.0
# crypto/x509
/usr/local/brew/Cellar/go/1.13/libexec/src/crypto/x509/root_cgo_darwin.go:16:10: fatal error: 'CoreFoundation/CoreFoundation.h' file not found
#include <CoreFoundation/CoreFoundation.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
2019/11/28 14:12:16 exit status 2

由于已经执行过 xcode-select --install 但没效果,于是执行如下操作:

  • 重启,按住 Command+R 进入 恢复模式,在恢复模式中选择 utilities > terminal,输入:csrutil disable
  • 点击 reboot 重启。
  • 运行sudo mount -uw /,使根目录可读写。
  • 然后执行如下命令:
cd /System/Library/Frameworks/CoreFoundation.framework
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers Headers
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Modules Modules
cd /System/Library/Frameworks/Security.framework
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers Headers
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Modules Modules

执行完后,再次执行 kubebuilder init,解决问题。