在Windows上使用VS Code构建时,遇到了Go ZeroMQ的链接器问题。

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

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

问题

简而言之,我想做以下事情:
使用https://github.com/pebbe/zmq4并在Windows上的VS Code中运行一个简单的示例,比如hello world
在构建过程中,我遇到了以下类型的错误:

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

到目前为止,我做了以下工作:

  • 安装了Visual Studio,因为vcpkg install要求安装它。
  • 使用vcpkg.exe install libzmq:x64-windows安装了libzmq(默认是32位安装,我之前错误地安装了它,希望没有残留导致问题)。
  • 在VS Code终端(PowerShell)中设置了所需的Go环境变量。经过一些尝试,我觉得应该这样做:
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'
  • 安装了TDM-GCC。
  • <Windows Homedir>\TDM-GCC-64\bin<Windows Homedir>\vcpkg\installed\x64-windows\lib<Windows Homedir>\vcpkg\installed\x64-windows\include添加到%Path%环境变量中。

我正在使用Go版本go1.18.4 windows/amd64和Windows 10 Enterprise上的VS Code 1.74.1。

我不知道接下来该尝试什么,所以非常感谢任何提示。

英文:

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.

答案1

得分: 1

我在链接器标志的语法上犯了一个错误。https://github.com/pebbe/zmq4让我走了一条错误的路。应该是CGO_LDFLAGS=' -L <Windows Homedir>/vcpkg/installed/x64-windows/lib -l libzmq-mt-4_3_4'

英文:

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=&#39;-L &lt;Windows Homedir&gt;/vcpkg/installed/x64-windows/lib -l libzmq-mt-4_3_4&#39;

huangapple
  • 本文由 发表于 2022年12月22日 00:43:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/74879175.html
匿名

发表评论

匿名网友

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

确定