[英]Get error when try to build Go code for Linux on Windows 10
I try to build Go code on Windows with CGO_ENABLED=1
. 我尝试在Windows上使用
CGO_ENABLED=1
构建Go代码。 I have a .bat file with 我有一个.bat文件
set GOOS=linux
set GOARCH=amd64
set CGO_CFLAGS=-g -O2 -w
set CGO_ENABLED=1
go build main.go constants.go functions.go
But I get error: 但是我得到了错误:
gcc_linux_amd64.c: In function '_cgo_sys_thread_start':
gcc_linux_amd64.c:62:2: error: unknown type name 'sigset_t'
sigset_t ign, oset;
^
What should I do? 我该怎么办? I could't find such error anywhere.
我在任何地方都找不到这样的错误。
PS If I haven't got "-w" flag in "CGO_CFLAGS" I will get this: PS:如果在“ CGO_CFLAGS”中没有“ -w”标志,我将得到以下信息:
# runtime/cgo
_cgo_export.c:1:0: error: -fPIC ignored for target (all code is position
independent) [-Werror]
/* Created by cgo - DO NOT EDIT. */
^
cc1.exe: all warnings being treated as errors
It seems that you need a cross compiler and the dev environment for compiling a C program for Linux. 看来您需要交叉编译器和dev环境才能为Linux编译C程序。 After searching around, this post may help: https://stackoverflow.com/a/4770417/3196456 .
在四处搜寻之后,这篇文章可能会有所帮助: https : //stackoverflow.com/a/4770417/3196456 。
Or, as you are using Windows 10, a more easier way is to try Windows Subsystem for Linux , which can give you a whole Linux development experience on Windows. 或者,当您使用Windows 10时,更简单的方法是尝试Windows Linux子系统 ,它可以为您提供Windows上的完整Linux开发经验。 If your Windows build is greater than 16215, you can directly install one through Microsoft Store, for example, Ubuntu .
如果您的Windows版本大于16215,则可以通过Microsoft Store直接安装一个版本,例如Ubuntu 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.