dtpwra8456 2018-03-04 20:30
浏览 3185
已采纳

尝试在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
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.

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
  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?