简体   繁体   English

尝试在Windows 10上为Linux构建Go代码时出错

[英]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.

相关问题 尝试构建Android应用程序时,Cordova失败,错误为“命令失败,退出代码2”,Linux - Cordova fail when try to build Android app with error “Command failed with exit code 2” Linux 二叉树代码适用于 Linux 但不适用于 Windows 10 - Binary tree code works on Linux but not on Windows 10 当我尝试运行从Windows系统编写的Linux脚本时出现“无此文件或目录”错误 - “No such file or directory” error when I try to run a Linux script written from Windows system 当我尝试在Linux上运行可执行文件时,出现“加载共享库时出错” - When I try to run the executable on Linux I get “error while loading shared libraries” Linux版monogame是否支持android解决方案? 尝试创建解决方案时出现错误 - Does monogame for linux support android solutions? I get an error when i try to create the solution Windows 10 Linux子系统上的Xming Visual Studio代码 - Xming Visual Studio Code on Windows 10 Linux Subsystem 为什么Python代码可以在Windows 10中运行,而不能在Linux中运行? - Why does Python code work in Windows 10 but not Linux? The same Web API Code works on Windows 10 but not on Linux Debian Buster - The same Web API Code works on Windows 10 but not on Linux Debian Buster 将NetBeans项目从Windows转移到Linux VM时,Ant生成错误 - Error with Ant build when transferring NetBeans project from Windows to Linux VM 在 Windows 中编辑代码但在 Linux 中构建和运行代码时如何使用 git 进行版本控制(使用 pycharm) - How to use git to do version control when I edit my code in Windows but build and run my code in Linux (using pycharm)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM