简体   繁体   English

Go ZeroMQ:尝试在 Windows 上构建 VS 代码时出现 Linker 问题

[英]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简而言之,我想做以下事情:使用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'

What I did so far:到目前为止我做了什么:

  • Install Visual Studio, since it was required by vcpkg install安装 Visual Studio,因为 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.)使用 vcpkg.exe install libzmq vcpkg.exe install libzmq:x64-windows (默认是 32 位安装,我首先错误地安装了它。我希望这个地方没有遗留问题。)
  • Set the required Go environment variables in VS Code Terminal (PowerShell).在 VS 代码终端 (PowerShell) 中设置所需的 Go 环境变量。 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安装 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添加<Windows Homedir>\TDM-GCC-64\bin , <Windows Homedir>\vcpkg\installed\x64-windows\lib<Windows Homedir>\vcpkg\installed\x64-windows\include到 %Path% 环境变量

I'm using Go version go1.18.4 windows/amd64 and VS Code 1.74.1 on Windows 10 Enterprise.我在 Windows 10 Enterprise 上使用 Go 版本 go1.18.4 windows/amd64 和 VS Code 1.74.1。

I have no clue what to try next, so any hints are very much appreciated.我不知道接下来要尝试什么,所以非常感谢任何提示。

I was using a wrong a wrong syntax for the linker flags.我对 linker 标志使用了错误的语法。 https://github.com/pebbe/zmq4 has lead me on a wrong track. https://github.com/pebbe/zmq4让我误入歧途。 It should be CGO_LDFLAGS='-L <Windows Homedir>/vcpkg/installed/x64-windows/lib -l libzmq-mt-4_3_4'应该是CGO_LDFLAGS='-L <Windows Homedir>/vcpkg/installed/x64-windows/lib -l libzmq-mt-4_3_4'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM