Go交叉编译CGO提示undefined

本文记录了在Linux环境下使用x86_64-w64-mingw32-gcc交叉编译Windows版Sciter代码时遇到的一系列未定义变量错误,并分享了解决方案:通过设置CGO_ENABLED环境变量为1成功编译。

在linux下面交叉编译windows版本的sciter的代码, 提示一堆未定义变量
编译linux版本的就没问题

$go build .
$CC=x86_64-w64-mingw32-gcc GOOS=windows go build .
# github.com/sciter-sdk/go-sciter
../../github.com/sciter-sdk/go-sciter/types_string.go:27:9: undefined: BehaviorEvent
../../github.com/sciter-sdk/go-sciter/types_string.go:62:9: undefined: MouseEvent
../../github.com/sciter-sdk/go-sciter/types_string.go:78:9: undefined: CursorType
../../github.com/sciter-sdk/go-sciter/types_string.go:89:9: undefined: KeyEvent
../../github.com/sciter-sdk/go-sciter/types_string.go:100:9: undefined: FocusEvent
../../github.com/sciter-sdk/go-sciter/types_string.go:111:9: undefined: ScrollEvent
../../github.com/sciter-sdk/go-sciter/types_string.go:122:9: undefined: GestureCmd
../../github.com/sciter-sdk/go-sciter/types_string.go:139:9: undefined: GestureState
../../github.com/sciter-sdk/go-sciter/types_string.go:171:9: undefined: GestureTypeFlag
../../github.com/sciter-sdk/go-sciter/types_string.go:197:9: undefined: DrawEvent
../../github.com/sciter-sdk/go-sciter/types_string.go:197:9: too many errors

查了半天, 发现是CGO_ENABLED的锅, 交叉编译的时候, 这个选项默认为0了, 手动设了后编译通过.

CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows go build .
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值