Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'stdlib.h' file not found under macOS Catalina 10.15.4 #39232

Closed
tonyleung815 opened this issue May 24, 2020 · 5 comments
Closed

'stdlib.h' file not found under macOS Catalina 10.15.4 #39232

tonyleung815 opened this issue May 24, 2020 · 5 comments

Comments

@tonyleung815
Copy link

@tonyleung815 tonyleung815 commented May 24, 2020

What version of Go are you using (go version)?

$ go version
go1.14.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
macOS Catalina 10.15.4 
$ 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/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/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=/var/folders/ml/3l4vgms54755dkmjmxztvj780000gn/T/go-build772202264=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

xcode-select --install
go run main.go

What did you expect to see?

Hello world !

What did you see instead?

runtime/cgo
_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found

I had installed the Command Line Tools by $xcode-select --install

@proyb6
Copy link

@proyb6 proyb6 commented May 24, 2020

Related #27921

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 24, 2020

What happens if you write a C file

#include <stdlib.h>
#include <stdio.h>

int main() { printf("Hello, world\n"); return 0; }

and try to compile that using cc main.c?

If you get the same error about stdlib.h, then the problem is with your C compiler installation, not with Go.

@tonyleung815
Copy link
Author

@tonyleung815 tonyleung815 commented May 25, 2020

Related #27921

Thanks for sharing, one of the comment in that issue works for me:
$ brew unlink llvm@4

@tonyleung815
Copy link
Author

@tonyleung815 tonyleung815 commented May 25, 2020

What happens if you write a C file

#include <stdlib.h>
#include <stdio.h>

int main() { printf("Hello, world\n"); return 0; }

and try to compile that using cc main.c?

If you get the same error about stdlib.h, then the problem is with your C compiler installation, not with Go.

Thanks for following up, below are my test result:
cc ok
gcc ok
clang: 'stdlib.h' file not found

The problem has been solved after I run: brew unlink llvm@4

@malajisi
Copy link

@malajisi malajisi commented Oct 6, 2020

From the discuss above and my issue( I installed an older version clang6 pkg and leave an export in my .bash_profile), all these caused by clang. So
FIRST check the environment in terminal with
clang -v
Change to use the Xcode installed clang, for macOS Catalina 10.15.4 is 11 or 12. All will done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.