2018-03-04 20:30
浏览 1.3k

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

I try to build Go code on Windows with CGO_ENABLED=1. I have a .bat file with

set GOOS=linux
set GOARCH=amd64
set CGO_CFLAGS=-g -O2 -w
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.

P.S. If I haven't got "-w" flag in "CGO_CFLAGS" I will get this:

# 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

图片转代码服务由CSDN问答提供 功能建议

我尝试使用 CGO_ENABLED = 1 在Windows上构建Go代码。 我有一个.bat文件,其中

  set GOOS = linux 
set GOARCH = amd64 
set CGO_CFLAGS = -g -O2 -w 
set CGO_ENABLED = 1 
go构建主体。 去constants.go functions.go 


  gcc_linux_amd64.c:在函数'  _cgo_sys_thread_start':
 sigset_t ign,oset; 

我应该怎么办 做? 我在任何地方都找不到这样的错误。

P.S。 如果我在“ CGO_CFLAGS”中没有“ -w”标志,则会得到以下信息:

 #runtime / cgo 
_cgo_export.c:1:0:错误:- 目标的fPIC被忽略(所有代码都与位置无关)[-Werror] 
 / *由cgo创建-请勿编辑。  * / 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • du0204 2018-03-15 10:51

    It seems that you need a cross compiler and the dev environment for compiling a C program for Linux. After searching around, this post may help: 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. If your Windows build is greater than 16215, you can directly install one through Microsoft Store, for example, Ubuntu.

    解决 无用
    打赏 举报

相关推荐 更多相似问题