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

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

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?