Golang zmq绑定,ZMQ4,返回找不到文件zmq.h的包错误。

huangapple go评论105阅读模式
英文:

Golang zmq binding, ZMQ4, returns package error not finding file zmq.h

问题

我正在尝试在Go应用程序中使用ZMQ套接字,但是zmq4和gozmq(Go的ZMQ绑定库)都给我带来了问题。我想了解为什么在我的系统上无法导入zmq4。

我正在运行Windows 8系统,并且我使用了ZMQ网站上版本4.0.3的Windows安装程序。我主要关心的是设置zmq4,以下是我在github库位置上运行"go get"查询的结果:

> 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.

即使克隆Github存储库,这个问题也没有得到解决-错误仍然相同。

我知道问题与位于ZMQ安装的“include”文件夹中的C库zmq.h有关,但是无论是路径问题还是外部工具问题导致了依赖关系的问题,这对我来说都是个谜。

在涉及到node.js的类似错误中,我看到其他人提到了一个解决方案,但在我的情况下并没有成功。

到目前为止,我已经将“include”文件夹的路径包含在我的PATH环境变量中,并且之前将zmq.h放在了zmq4的顶级文件夹中。除此之外,由于我对C和在Go中导入包的知识很少,我没有其他方法来理解这个问题。

英文:

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

答案1

得分: 2

我想做同样的事情,但在Windows 7上,这是我必须做的。

由于Go绑定使用cgo与zeromq集成,所以你需要使用gcc构建zeromq。没有预编译的二进制文件,所以你需要自己构建它们,可以使用mingw或类似的工具,但这个过程比听起来的要简单,并且在zeromq网站上有很好的描述。

正如@photoionized指出的那样,在构建Go绑定时需要设置C_INCLUDE_PATHLIBRARY_PATH

(在我的情况下,当编译libzmq时,我遇到了IN6_ADDR未定义的问题。我找到的唯一解决办法是,受到this issue的启发,手动在windows.hpp文件中添加一行#include <in6addr.h>。)

英文:

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.)

答案2

得分: 2

ZeroMQ的Windows安装程序版本无法与zmq4一起使用,您需要使用gcc从源代码编译,我建议使用MSYS2。

  1. 根据以下说明安装和更新MSYS2:
    http://sourceforge.net/p/msys2/wiki/MSYS2%20installation/
  2. 根据Go的架构(32位或64位),启动mingw32_shell.bat或mingw64_shell.bat。
  3. 运行命令pacman -S mingw-w64-(x86_64|i686)-toolchain make(64位使用x86_64,32位使用i686)。
  4. 进入zeromq源代码文件夹(C:\路径在shell中表示为/c/)。
  5. 运行命令./configure
  6. 运行命令make
  7. 运行命令make install
  8. 运行命令CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go get github.com/pebbe/zmq4
  9. 将以下dll文件复制到您的go程序(.exe)旁边:
    /usr/local/bin/libzmq.dll
    /mingw(32|64)/bin/libgcc*.dll
    /mingw(32|64)/bin/libwinpthread*.dll
    /mingw(32|64)/bin/libstdc++*.dll
英文:

The Windows installer version of ZeroMQ won't work with zmq4, you need to compile from source with gcc, I recommend using MSYS2.

  1. Install and update MSYS2 following the instructions from
    http://sourceforge.net/p/msys2/wiki/MSYS2%20installation/
  2. Start the mingw32_shell.bat or mingw64_shell.bat based on Go arch (32bit or 64bit)
  3. pacman -S mingw-w64-(x86_64|i686)-toolchain make (x86_64 for 64bit, i686 for 32bit)
  4. cd into zeromq src folder (C:\ path starts with /c/ inside the shell)
  5. ./configure
  6. make
  7. make install
  8. CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go get github.com/pebbe/zmq4
  9. Copy 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

答案3

得分: 0

以下是@user2172816的MSYS2解决方案的更新步骤:

  1. 根据http://sourceforge.net/p/msys2/wiki/MSYS2%20installation/上的说明安装和更新MSYS2。

  2. 根据Go的架构(32位或64位),启动mingw32_shell.batmingw64_shell.bat

  3. 运行命令pacman -S mingw-w64-(x86_64|i686)-toolchain make(64位使用x86_64,32位使用i686)。

  4. C:\msys64\mingw64\bin添加到系统环境变量Path中(pkg-config位于此处)。

  5. 重新启动msys2 shell以获取新的Path。

  6. 下载并解压libsodium源代码:https://github.com/jedisct1/libsodium/releases。

  7. 进入libsodium文件夹(C:\路径在shell中以/c/开头)。

  8. 运行命令./configure --build=(x86_64|i686)-w64-mingw32

  9. 运行命令make

  10. 运行命令make install

  11. /usr/local/lib添加到PKG_CONFIG_PATH中(export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig)。

  12. 进入zeromq源代码文件夹。

  13. 运行命令./configure --build=(x86_64|i686)-w64-mingw32

  14. 将以下内容添加到src/tcpaddress.cpp文件的顶部:

    #ifdef ZMQ_HAVE_MINGW32

    #include <winsock2.h>

    #include <windows.h>

    #include "netioapi.h"

    #endif

  15. 运行命令make

  16. 运行命令make install

  17. 在项目目录中运行命令CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go get github.com/pebbe/zmq4

  18. 在项目目录中运行命令CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go build

  19. 将以下dll文件复制并放置在与您的Go程序(.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

也许还有:/usr/local/bin/libsodium-*.def

英文:

Here's updated steps for @user2172816's MSYS2 solution:

  1. Install and update MSYS2 following the instructions from http://sourceforge.net/p/msys2/wiki/MSYS2%20installation/

  2. Start the mingw32_shell.bat or mingw64_shell.bat based on Go arch (32bit or 64bit)

  3. pacman -S mingw-w64-(x86_64|i686)-toolchain make (x86_64 for 64bit, i686 for 32bit)

  4. Add C:\msys64\mingw64\bin to your Path (pkg-config is there)

  5. Restart the msys2 shell to get the new Path

  6. Download and unzip libsodium source: https://github.com/jedisct1/libsodium/releases

  7. cd into libsodium folder (C:\ path starts with /c/ inside the shell)

  8. ./configure --build=(x86_64|i686)-w64-mingw32

  9. make

  10. make install

  11. Add /usr/local/lib to PKG_CONFIG_PATH (export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig)

  12. cd into zeromq src folder

  13. ./configure --build=(x86_64|i686)-w64-mingw32

  14. Add

    #ifdef ZMQ_HAVE_MINGW32

    #include &lt;winsock2.h&gt;

    #include &lt;windows.h&gt;

    #include &quot;netioapi.h&quot;

    #endif

To the top of src/tcpaddress.cpp

  1. make

  2. make install

  3. CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go get github.com/pebbe/zmq4

  4. CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go build in your project directory

  5. Copy 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

答案4

得分: 0

使用MSYS2进行更新的答案。

  1. 安装MSYS2 MSYS2安装指南

  2. 确保选择正确的安装32位或64位。

  3. 打开适当的shell MSYS2 MinGW 64位MSYS2 MinGW 32位后续所有步骤都假设您正在使用此shell

  4. 根据安装指南中的说明更新软件包。

  5. 安装libtool pacman -Sy libtool

  6. zmq源代码下载到您选择的位置。

  7. 导航到zmq源文件夹。

  8. 运行自动生成工具./autogen.sh生成configure文件。

  9. 在可能的情况下,如果步骤8失败:

    1. 找到故障的file(可能是version.sh)。

    2. 通过以下方式替换行尾(将file替换为实际的文件名)。
      cp file file.bak

      tr -d '\r' <file.bak> file

    3. 如果这失败了,您将不得不深入代码并找到问题。

  10. 运行配置工具./configure

  11. 在可能的情况下,如果失败,请注释掉配置文件中的空else子句。

  12. 将Go添加到PathPATH=${PATH}:<go bin directory>

  13. 安装Go包:CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go get github.com/pebbe/zmq4

英文:

An updated answer using MSYS2.

  1. Install MSYS2 MSYS2 installation guide.

  2. Make sure to choose the correct installation 32bit or 64bit.

  3. Open the appropriate shell MSYS2 MinGW 64-bit or MSYS2 MinGW 32-bit. All further steps assume you are using this shell.

  4. Update packages following instructions at the installation guide.

  5. Install libtool pacman -Sy libtool.

  6. Download zmq source code to a location of your choice.

  7. Navigate to the zmq source folder.

  8. To generate the configure file, run the autogen tool by running ./autogen.sh.

  9. In the probable case that step 8 fails:

    1. Find the file at fault (probably version.sh).

    2. Replace line endings by (replace file by the actual filename).
      cp file file.bak

      tr -d &#39;\r&#39; &lt;file.bak&gt; file

    3. If this fails you'll have to dive in the code and find the problem.

  10. Run the configure tool ./configure.

  11. In the probable case of failure. Comment out empty else clauses in the configure file.

  12. Add Go to Path: PATH=${PATH}:&lt;go bin directory&gt;.

  13. Install Go Package: CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go get github.com/pebbe/zmq4

答案5

得分: 0

在Windows上安装ZMQ的步骤如下:

首先,安装msys64。从https://www.msys2.org/下载该软件,并将其安装在C:\msys64目录下。

然后将C:\msys64\mingw64\bin添加到Windows的PATH环境变量中。

接下来,在CMD中逐个运行以下命令:

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

最后,运行Go的安装命令:

go get github.com/pebbe/zmq4

完成。

英文:

To install ZMQ in windows: https://stackoverflow.com/questions/70839950/problem-in-installing-golang-zmq-for-windows-fatal-error-czmq-h-no-such-file

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.

huangapple
  • 本文由 发表于 2014年3月7日 11:05:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/22240636.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定