英文:
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='-L <Windows Homedir>/vcpkg/installed/x64-windows/lib -l libzmq-mt-4_3_4'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论