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

PHPz
Release: 2024-02-14 23:10:14
forward
1305 people have browsed it

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'
Copy after login

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'
Copy after login
  • Install tdm-gcc
  • Add<windows homedir>\tdm-gcc-64\bin, <windows homedir>\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 <Windows Homedir>/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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template