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

尝试在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 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示