Search code examples
windowsgozeromq

Go ZeroMQ: Linker problem when trying to build in VS Code on Windows


In short, I want to do the following thing: Use https://github.com/pebbe/zmq4 and run a simple example, like hello world in VS Code on Windows. When building, I get these kinds of errors

<Windows Homedir>/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: $WORK\b299\_x008.o: in function `zmq4_bind':
<GOPATH>/pkg/mod/github.com/pebbe/zmq4@v1.2.9/wrappers_windows.go:27: undefined reference to `__imp_zmq_bind'

What I did so far:

  • Install Visual Studio, since it was required by vcpkg install
  • Install libzmq using vcpkg.exe install libzmq:x64-windows (default is 32 bit installation, which I did first by mistake. I hope there is no leftover from this somewhere that's causing problems.)
  • Set the required Go environment variables in VS Code Terminal (PowerShell). After some trying, it seemed to me that this has to be done like this:
go env -w CGO_CFLAGS='-I <Windows Homedir>\vcpkg\installed\x64-windows\include'
go env -w CGO_LDFLAGS='-LD:<Windows Homedir>\vcpkg\installed\x64-windows\lib -L:libzmq-mt-4_3_4.lib'
  • Install TDM-GCC
  • Add <Windows Homedir>\TDM-GCC-64\bin, <Windows Homedir>\vcpkg\installed\x64-windows\lib and <Windows Homedir>\vcpkg\installed\x64-windows\include to %Path% environment variable

I'm using Go version go1.18.4 windows/amd64 and VS Code 1.74.1 on Windows 10 Enterprise.

I have no clue what to try next, so any hints are very much appreciated.


Solution

  • I was using a wrong a wrong syntax for the linker flags. https://github.com/pebbe/zmq4 has lead me on a wrong track. It should be CGO_LDFLAGS='-L <Windows Homedir>/vcpkg/installed/x64-windows/lib -l libzmq-mt-4_3_4'