Home  >  Article  >  Backend Development  >  Go ZeroMQ: Linker issues when trying to build VS Code on Windows

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

PHPz
PHPzforward
2024-02-14 23:10:141304browse

Go ZeroMQ:尝试在 Windows 上构建 VS Code 时出现链接器问题

php editor Zimo encountered a linker problem when trying to use Go ZeroMQ on a Windows system when building VS Code. This problem occurs during compilation and causes the build to fail. In order to solve this problem, the editor conducted a series of investigations and attempts, and finally found a solution. This article will introduce the background and causes of this linker problem in detail, and share the solution, hoping to help other developers solve similar problems quickly.

Question content

In short, I want to do the following: Use https://github.com/pebbe/zmq4 and run a simple example like hello world in vs code on windows. When building, I get these types 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/[email&#160;protected]/wrappers_windows.go:27: undefined reference to `__imp_zmq_bind'

What I've done so far:

  • Install visual studio because it is required for vcpkg installation
  • Install libzmq using vcpkg.exe install libzmq:x64-windows (Default is a 32-bit install, this is the first time I did it by mistake. I hope there aren't any leftovers causing problems. )
  • Set the required go environment variables in the vs code terminal (powershell). After some trying, it seems to me that this must be done:
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
  • Add463db8000df5bbb698520c066bc41f09\tdm-gcc-64\bin, 463db8000df5bbb698520c066bc41f09\vcpkg\installed\x64-windows\lib and &lt ;windows homedir>\vcpkg\installed\x64-windows\include to %path% environment variable

I am using go version go1.18.4 windows/amd64 and vs code 1.74.1 on windows 10 enterprise.

I don't know what to try next, so any tips are greatly appreciated.

Solution

I used the wrong syntax for the linker flags. https://github.com/pebbe/zmq4 Put me on the wrong path. It should be CGO_LDFLAGS='-L d56d737ffc497ec92db023dcb17d6ed5/vcpkg/installed/x64-windows/lib -l libzmq-mt-4_3_4'

The above is the detailed content of Go ZeroMQ: Linker issues when trying to build VS Code on Windows. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete