cgo在原始的Go和原始的Cygwin上似乎无法正常工作 – 它是否得到支持?

huangapple go评论92阅读模式
英文:

cgo seems broken on stock go on stock cygwin - is it supported?

问题

在当前的Cygwin环境下,运行任何使用cgo的简单的“Hello, world!”程序都会生成一个错误。错误信息显示隐式声明函数'_beginthread',并将所有警告视为错误。

这可能是因为Cygwin环境不支持Go语言,或者可能是由于某些配置问题导致的。要解决此问题,你可以尝试以下几个步骤:

  1. 确保你的Cygwin环境已正确安装并配置了Go语言。
  2. 确保你的Go版本是最新的,并且与Cygwin环境兼容。
  3. 检查你的代码中是否存在任何与Cygwin环境不兼容的部分,并进行相应的修改。
  4. 尝试在其他支持Go语言的环境中运行相同的代码,以确定是否是Cygwin环境的问题。

希望这些步骤能帮助你解决问题。如果问题仍然存在,请提供更多详细信息,以便我能够更好地帮助你。

英文:

Running any simple "Hello, world!" that uses cgo on a (current as of today) stock cygwin generates an error:

> $ go version
> go version go1.16.5 windows/amd64
>
> $ go test -run TestCamera
> # runtime/cgo
> gcc_libinit_windows.c: In function ‘x_cgo_sys_thread_create’:
> gcc_libinit_windows.c:58:12: error: implicit declaration of function ‘_beginthre
> ad’ [-Werror=implicit-function-declaration]
> 58 | thandle = _beginthread(func, 0, arg);
> | ^~~~~~~~~~~~
> cc1: all warnings being treated as errors

Is go not supported on cygwin for some reason? Or, how can I fix this?

example code: literally any cgo, for example https://github.com/kyleconroy/hello-cgo/blob/master/hello.go

答案1

得分: 2

如果我下载这些文件[1],我可以按预期运行以下命令:

PS C:\hello-cgo> go mod init hello
PS C:\hello-cgo> go build
PS C:\hello-cgo> .\hello.exe
Hello CGO!

然而,我应该说明我并没有使用Cygwin,而是使用MSYS2 [2]。具体来说,这些软件包:

mingw-w64-x86_64-gcc
mingw-w64-x86_64-binutils
mingw-w64-x86_64-crt-git
mingw-w64-x86_64-gmp
mingw-w64-x86_64-headers-git
mingw-w64-x86_64-libwinpthread-git
mingw-w64-x86_64-windows-default-manifest
mingw-w64-x86_64-winpthreads-git
mingw-w64-x86_64-zlib
mingw-w64-x86_64-zstd

我认为如果你使用Pacman,你只需要安装第一个软件包,它会自动安装其余的软件包(我使用自己的MSYS2软件包管理器)。我知道这不完全是你所要求的,但也许对你有所帮助。

  1. https://github.com/kyleconroy/hello-cgo
  2. https://repo.msys2.org/distrib
英文:

If I download these files [1], I can run these commands as expected:

PS C:\hello-cgo> go mod init hello
PS C:\hello-cgo> go build
PS C:\hello-cgo> .\hello.exe
Hello CGO!

However I should say that I am not using Cygwin, but MSYS2 [2]. Specifically, these
packages:

mingw-w64-x86_64-gcc
mingw-w64-x86_64-binutils
mingw-w64-x86_64-crt-git
mingw-w64-x86_64-gmp
mingw-w64-x86_64-headers-git
mingw-w64-x86_64-libwinpthread-git
mingw-w64-x86_64-windows-default-manifest
mingw-w64-x86_64-winpthreads-git
mingw-w64-x86_64-zlib
mingw-w64-x86_64-zstd

I think if you use Pacman, you can just install the first one, and it will pull
in the rest (I use my own MSYS2 package manager). I know this is not quite what
you asked for, but maybe it will help you.

  1. https://github.com/kyleconroy/hello-cgo
  2. https://repo.msys2.org/distrib

答案2

得分: 0

在安装了mingw64-x86_64-gcc-core并按照https://stackoverflow.com/a/43615612/2935741上的描述设置了export CC='D:\cygwin64\bin\x86_64-w64-mingw32-gcc.exe'之后,我在Cygwin上运行Go没有任何问题。

英文:

I have no problems running go on cygwin after installing mingw64-x86_64-gcc-core and
export CC='D:\cygwin64\bin\x86_64-w64-mingw32-gcc.exe' as described on https://stackoverflow.com/a/43615612/2935741.

huangapple
  • 本文由 发表于 2021年6月7日 11:31:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/67865634.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定