[英]Compile go program with C dependency for Windows
Building go works fine for pure go project with pure go dependencies.对于具有纯 go 依赖项的纯 go 项目,构建 go 工作正常。 But when building a project with a C dependency, it fails on Windows:但是在构建具有 C 依赖项的项目时,它在 Windows 上失败:
go build -a -o bin/xyz.exe ./xyz/main.go
go: downloading gopkg.in/confluentinc/confluent-kafka-go.v1 v1.4.2
go: downloading github.com/confluentinc/confluent-kafka-go v1.4.2
# gopkg.in/confluentinc/confluent-kafka-go.v1/kafka
In file included from C:\Users\VssAdministrator\go\pkg\mod\gopkg.in\confluentinc\confluent-kafka-go.v1@v1.4.2\kafka\00version.go:24:
./librdkafka/rdkafka.h:83:10: fatal error: sys/socket.h: No such file or directory
#include <sys/socket.h> /* for sockaddr, .. */
^~~~~~~~~~~~~~
compilation terminated.
mingw32-make: *** [Makefile:10: build-windows] Error 2
##[error]Cmd.exe exited with code '2'.
Finishing: CmdLine
As can be seen from the output above, I'm using a Makefile, and my azure-pipelines.yml looks like this:从上面的输出可以看出,我使用的是 Makefile,我的 azure-pipelines.yml 如下所示:
...
- script: 'make package-windows'
...
Here's my Makefile:这是我的 Makefile:
build-windows:
go build -a -o bin/xyz.exe ./xyz/main.go
I also tried setting GOOS and GOARCH, to no avail:我也试过设置 GOOS 和 GOARCH,无济于事:
build-windows:
GOOS=windows GOARCH=amd64 go build -a -o bin/xyz.exe ./xyz/main.go
So how can I build this?那么我该如何构建它呢?
This doesn't have much to do with Go - it seems you're doing everything correctly in that regard.这与 Go 没有太大关系 - 似乎你在这方面做的一切都是正确的。 The issue is that the library you're using needs sys/socket.h
which simply doesn't exist on Windows (see Using sys/socket.h functions on windows ).问题是您使用的库需要sys/socket.h
,而 Windows 上根本不存在它(请参阅在 Windows 上使用 sys/socket.h 函数)。
Your options are similar to what's mentioned in the other answer:您的选项类似于其他答案中提到的选项:
sys/socket.h
.修改库以使用 Winsock 而不是sys/socket.h
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.