-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime/cgo: macro expansion producing 'defined' has undefined behavior #38876
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
Comments
This is a dup of #38552 but you provided a reproducer so let's keep this one and I'll close the other thread. |
What do you see if you create a file foo.c containing #include <string.h>
#include <pthread.h> and then run
? |
|
Thanks. Seems to me that your C compiler is broken, or at least that it doesn't agree with your library. Is there some option that we can pass to the compiler to disable this pointless error? Does it work if you run
? |
A new error has occurred.
|
I really don't understand that one. That said, why it is including from /usr/local/include? Is that where standard library header files live on Darwin? Or is there another <pthread.h> that it should be using instead? What happens if you temporarily remove /usr/local/include/pthread.h and compile foo.c? |
Hi! My program is the same than yours and I was able to make it work using this. |
Thank you all for your help. I finally found out that my Xcode command line tools can not work as expectation. What I did is to run these lines in Terminal.
|
FWIW I had the same issue (different codebase, tried using OP's code and reproduced issue), and reinstalling xcode did NOT fix it. Installing gcc with brew and then explicitly setting CC and CXX to the symlinked gcc binaries did fix it. |
This works for me except |
So i noticed this issue on MacOs Catalina 10.15.4 as well, out of the blue. I tried the solution that @Sr0121 suggested, didn't work, I also tried the reinstalling gcc as per @stephanGarland's comment, to no avail. Finally I upgraded 10.15.5 and did the above as well, still didn't change anything. I had to add compiler flags as per @victorneuret . Kind of annoying how this came out of the blue. |
@erikterwiel That worked for me as well! |
found out.. I recently symlinked gcc headers into usr/local/include to get some other project running. |
Yea I think I did something similar to get it working. |
where to add and how? |
how to do it? |
@kangkang59812 Then check your environment via |
One more problem is that I got permission denied after using the
I need to grant permission to /usr/local/go for it to work. I think this should be handled by the installer? |
Thanks, this works fom me! |
Hi!
|
Problems solved. I reinstalled |
I met the same issue when using gvm to install go1.16 in Big Sur. Your solution totally works! mac@macdeMac-mini ~ % gvm install go1.16
Downloading Go source...
Installing go1.16...
* Compiling...
ERROR: Failed to compile. Check the logs at /Users/mac/.gvm/logs/go-go1.16-compile.log
ERROR: Failed to use installed version
mac@macdeMac-mini ~ %
mac@macdeMac-mini ~ % cat /Users/mac/.gvm/logs/go-go1.16-compile.log
Building Go cmd/dist using /usr/local/go. (go1.17.1 darwin/amd64)
Building Go toolchain1 using /usr/local/go.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for darwin/amd64.
# 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'
go tool dist: FAILED: /Users/mac/.gvm/gos/go1.16/pkg/tool/darwin_amd64/go_bootstrap install -gcflags=all= -ldflags=all= std cmd: exit status 2
mac@macdeMac-mini ~ % export CGO_CPPFLAGS="-Wno-error -Wno-nullability-completeness -Wno-expansion-to-defined -Wno-builtin-requires-header"
mac@macdeMac-mini ~ % gvm install go1.16
Installing go1.16...
* Compiling...
go1.16 successfully installed! |
This
The macro expansion is not properly parenthesized. The macro is used this way in the same file:
Which expands to:
The This seems to be a bug in |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?OS: macOS Catalina 10.15.4
go env
OutputWhat did you do?
Try to run this code:
What did you expect to see?
Expect the program to run.
What did you see instead?
The text was updated successfully, but these errors were encountered: