Reputation: 103
I am trying to include ZMQ sockets in a Go app but both zmq4 and gozmq (the referred ZMQ binding libraries for Go) are giving me problems. I would like to understand why zmq4 specifically isn't importable on my system.
I am running a Windows 8 system and I used the windows installer from the ZMQ website for version 4.0.3. I am primarily concerned about getting zmq4 set up and here is the result of my "go get" query on the github library's location:
> go get github.com/pebbe/zmq4
# github.com/pebbe/zmq4
polling.go:4:17: fatal error: zmq.h: No such file or directory
compilation terminated.
This issue is not alleviated by cloning the Github repository - the error remains the same.
I know the issue has to do with the C library zmq.h that is located in the "include" folder of my ZMQ installation, but whether the dependency is held up by a pathing issue or an external tool issue is a mystery to me.
A similar error has come up in regards to node.js and is the solution I see others referred to, outside of node scripting, but it was unsuccessful in my case.
I've so far included the path to the "include" folder in my PATH environment variable and previously placed zmq.h inside of the zmq4 top-level folder. I don't have much of an arsenal otherwise to understand this problem because I am new to C and C-importing packages in Go
Upvotes: 5
Views: 4384
Reputation: 1525
To install ZMQ in windows: Problem in Installing Golang ZMQ for windows - fatal error: czmq.h: No such file or directory
First of all, install the msys64
. Download the software from https://www.msys2.org/ and install it on C:\msys64
.
Then add C:\msys64\mingw64\bin
to PATH
environment variable of the windows.
Then run the following commands (in CMD) one by one.
pacman -Su
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
pacman -S base-devel gcc vim cmake
pacman -S mingw-w64-x86_64-libsodium
pacman -S mingw-w64-x86_64-zeromq
Finally, run the Go
install command:
go get github.com/pebbe/zmq4
Finished.
Upvotes: 1
Reputation: 91
An updated answer using MSYS2.
MSYS2 MinGW 64-bit
or MSYS2 MinGW 32-bit
. All further steps assume you are using this shell.pacman -Sy libtool
../autogen.sh
. In the probable case that step 8 fails:
file
at fault (probably version.sh
).Replace line endings by (replace file
by the actual filename).
cp file file.bak
tr -d '\r' <file.bak> file
Run the configure tool ./configure
.
In the probable case of failure. Comment out empty else
clauses in the configure file.
Add Go to Path
: PATH=${PATH}:<go bin directory>
.
CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go get github.com/pebbe/zmq4
Upvotes: 0
Reputation: 784
Here's updated steps for @user2172816's MSYS2 solution:
mingw32_shell.bat
or mingw64_shell.bat
based on Go arch (32bit or 64bit)pacman -S mingw-w64-(x86_64|i686)-toolchain make
(x86_64 for 64bit, i686 for 32bit)C:\msys64\mingw64\bin
to your Path (pkg-config is there)cd
into libsodium folder (C:\ path starts with /c/ inside the shell)./configure --build=(x86_64|i686)-w64-mingw32
make
make install
/usr/local/lib
to PKG_CONFIG_PATH
(export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
)./configure --build=(x86_64|i686)-w64-mingw32
Add
#ifdef ZMQ_HAVE_MINGW32
#include <winsock2.h>
#include <windows.h>
#include "netioapi.h"
#endif
To the top of src/tcpaddress.cpp
make
make install
CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go get github.com/pebbe/zmq4
CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go build
in your project directoryCopy the following dlls and put them next to your go program (.exe):
/usr/local/bin/libzmq.dll
/mingw(32|64)/bin/libgcc*.dll
/mingw(32|64)/bin/libwinpthread-*.dll
/mingw(32|64)/bin/libstdc++*.dll
/usr/local/bin/libsodium-*.dll
maybe? /usr/local/bin/libsodium-*.def
Upvotes: 0
Reputation: 1200
The Windows installer version of ZeroMQ won't work with zmq4, you need to compile from source with gcc, I recommend using MSYS2.
pacman -S mingw-w64-(x86_64|i686)-toolchain make
(x86_64 for 64bit, i686 for 32bit)cd
into zeromq src folder (C:\ path starts with /c/ inside the shell)./configure
make
make install
CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go get github.com/pebbe/zmq4
/usr/local/bin/libzmq.dll
/mingw(32|64)/bin/libgcc*.dll
/mingw(32|64)/bin/libwinpthread*.dll
/mingw(32|64)/bin/libstdc++*.dll
Upvotes: 2
Reputation: 785
I wanted to do the same thing, but on Windows 7, and here is what I had to do.
Since the Go bindings are using cgo to integrate with zeromq, you need zeromq built with gcc. There are no pre-built binaries, so you'll have to build them yourself, with mingw or similar, but this process is easier than it may sound, and nicely described on the zeromq site.
As @photoionized pointed out, C_INCLUDE_PATH
and LIBRARY_PATH
need to be set when building the Go bindings.
(In my case, I ran into a problem when compiling libzmq with IN6_ADDR
not being defined. The only solution I found was, inspired by this issue, to manually add the line #include <in6addr.h>
to the windows.hpp file.)
Upvotes: 2