0

Building go works fine for pure go project with pure go dependencies. But when building a project with a C dependency, it fails on 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:

...
- script: 'make package-windows'
...

Here's my Makefile:

build-windows:
    go build -a -o bin/xyz.exe ./xyz/main.go

I also tried setting GOOS and GOARCH, to no avail:

build-windows:
    GOOS=windows GOARCH=amd64 go build -a -o bin/xyz.exe ./xyz/main.go

So how can I build this?

Evgeniy Berezovsky
  • 18,571
  • 13
  • 82
  • 156

1 Answers1

1

This doesn't have much to do with Go - it seems you're doing everything correctly in that regard. 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).

Your options are similar to what's mentioned in the other answer:

  1. Try to build using Cygwin.
  2. Modify the library to use Winsock instead of sys/socket.h.
  3. Find a different library, one that supports Windows (the author of the library you're using specifically said Windows is not supported).
fstanis
  • 5,234
  • 1
  • 23
  • 42
  • Thanks. librdkafka does [support Windows](https://github.com/edenhill/librdkafka/tree/master/win32) via msbuild, but confluent-kafka does in fact not seem to officially, although a couple of people have managed to [build it on Windows](https://github.com/confluentinc/confluent-kafka-go/issues/128) with and without Cygwin - I will check that out. – Evgeniy Berezovsky Oct 05 '20 at 00:34