-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
runtime/cgo: gcc_libinit_windows.c:136:27: error: implicit declaration of function '_beginthread' #59490
Comments
CC @golang/compiler maybe? |
Hello, @mknyszek. Well, using another compiler can unveil a whole box of surprises. Take native compilers for Windows OS for example ... By the way, is it possible to use Microsoft's compiler from Visual Studio Community 2022 together with Golang's CGO ? I am using Windows OS, and GCC compiler does not support many things which I need on the Windows platform. Using a compiler from Unix / Linux world on Windows looks very strange, to say the least. P. S.
https://docs.oracle.com/cd/E19205-01/819-5265/bjazh/index.html |
Looks like the reason was in the Cygwin64. I deleted it and used another bundle of 64-bit MinGW.
|
OK. I have added a header file for
Now the error is different.
How do I cast Go's uintptr to C's pointer to char ? |
leads to an error:
Full code is following.
|
Looks like, the If I change the last statement
to
It compiles and runs.
|
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/beginthread-beginthreadex it seems
Issue #20982 is about MSVC support. Is there anything you expect beyond that issue? Thanks. |
I have no idea about Cygwin64. This project is very strange to me. I prefer MS Visual Studio with its MSVC compiler and LLVM with its CLang compiler, but it looks like they are both not supported by Google at this moment. And, for some reason Golang does not provide a way to select a compiler for C language in CGO.
I expect that Google adds a possibility to change a compiler for C language in CGO in Golang. P. S. There is a great thing in this field. LLVM. The LLVM project tries to unify compilers of different languages and different vendors and make it possible to use a common standard for compiling and linking executables. I think, Google should think about supporting this truly cross-platform solution. Here is an extract from Wikipedia about it.
|
I think we do support LLVM based C compiler for Windows. Have you tried that?
We have "gollvm" project that uses LLVM backend for Go https://go.googlesource.com/gollvm . You're welcome to try that. It doesn't support Windows yet, though. But that is beyond the scope of this issue. Thanks. |
I tried to compile CGO code with CLang compiler, but it threw a lot of errors about GCC parameters passed to CLang.
Why ? |
I hit this issue using "Git for Windows SDK" for my mingw, turns out I had forgotten to add the environment variable "MSYSTEM" = "MINGW64" after a clean windows install. Hopefully this information can help someone else. |
Can you show us the exact output? Thanks. |
|
Those errors are all coming from the linker. We currently expect that clang will be used with a clang linker such as lld. |
Is it possible for a user to change the linker ? |
I'm sure it is, because I see that lld supports Windows. But I don't know enough about Windows to tell you how to do it. Sorry. |
@ianlancetaylor , do you mean Linux's symlinks ? This does not look like a setting to me :-) |
Sorry, I don't understand what you mean about symlinks. When I mention lld I mean https://lld.llvm.org/. The Go tools use the environment variable There must be some way to install clang on Windows such that it runs lld as the linker. |
CMake has an interesting feature. It is possible to tell CMake how to use the linker.
https://stackoverflow.com/questions/1867745/cmake-use-a-custom-linker I thought about something like this. |
Is it possible in CGO to pass a custom argument to the compiler specified in I know how to tell the CLang compiler use the LLD ( |
Set |
I tried to run the CLang compiler with LLD ( Is there a verbose mode in CGO to print all the executed commands into stdout for debugging ? |
|
What is the difference between CFLAGS and CGO_CFLAGS ? |
Bother, you're right. My apologies. It should be |
Actually, it is not clear from the documentation (https://pkg.go.dev/cmd/cgo), how to use these variables. |
In general the flags from the environment variables follow the flags from a |
@vault-thirteen Are you still seeing the implicit declaration error? Should we leave this issue open? |
@mknyszek , if I install the Cygwin64, then I will see it, so yes, it is not working with Cygwin64. |
I ran into the same problem:
I see no problem within the code for:
I will be trying this out later: https://github.com/goreleaser/goreleaser-cross |
I further checked the location of the process.h file, on my machine it's located here: (maybe the compiler is finding another header file?) -- investigating this now.
and when I run this I can see where gcc is looking:
It's not finding the windows sdk header... but some other header file. |
After using the CGO_FLAGS to specify additional search paths for gcc, I got this type of errors, and adding more paths, adds more errors... all the way up to
|
this got me unblocked: (using
Also I am not yet able to target windows |
that happen because you installed gcc through cygwin64 if it needs to CG_ENABELED=1 |
删除 其他的gcc 环境 只是用tdm-gcc ,就可以编译成功 |
In this package, the search |
Thanks @injuryzy ,it works on my windows11! |
What version of Go are you using (
go version
)?1.20.3
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Windows 10
Intel x86-64
What did you do?
I tried to run a simple code to execute a function from a DLL file.
CGO is enabled, gcc is installed with Cygwin64 and has version 11.3.0-1.
SDL is the latest version, 2.26.5.
What did you expect to see?
I expected not to see errors at compile time.
What did you see instead?
The text was updated successfully, but these errors were encountered: