VSCode搭配MinGW-w64使用ZeroMQ时zmq.hpp文件未找到的编译错误解决问询
VSCode搭配MinGW-w64使用ZeroMQ时zmq.hpp文件未找到的编译错误解决问询
我正在开发一个C++项目,使用ZeroMQ库实现与Python、MetaTrader 4(MT4)的通信,开发环境为Windows系统下的VSCode,编译器选用MinGW-w64。
已执行的操作步骤
- 克隆cppzmq仓库
git clone https://github.com/zeromq/cppzmq.git
- 创建ZeroMQ头文件存储目录
mkdir C:\ZeroMQ\include\cppzmq
- 将zmq.hpp复制到头文件目录
Copy-Item "C:\Users\Leonardo Alves\Desktop\Python Projects\project_socket\cppzmq\zmq.hpp" "C:\ZeroMQ\include\cppzmq\"
- 配置VSCode的tasks.json文件
{ "version": "2.0.0", "tasks": [ { "label": "Build DLL (Debug)", "type": "shell", "command": "g++", "args": [ "-shared", "-o", "output/mq4socket.dll", "mq4socket.cpp", "-I", "C:/ZeroMQ/include", "-L", "C:/ZeroMQ/lib", "-lzmq", "-g" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": ["$gcc"] }, { "label": "Build Test App (Debug)", "type": "shell", "command": "g++", "args": [ "-o", "output/test_app.exe", "test_app.cpp", "-I", "C:/ZeroMQ/include", "-L", "C:/ZeroMQ/lib", "-lzmq", "-g" ], "group": { "kind": "build", "isDefault": false }, "problemMatcher": ["$gcc"] } ] }
- 配置VSCode的c_cpp_properties.json文件
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:/ZeroMQ/include" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "C:/mingw64/bin/g++.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64" } ], "version": 4 }
遇到的编译错误
尝试编译mq4socket.cpp时,出现以下致命错误:
c:\Users\Leonardo Alves\Desktop\Python Projects\project_socket\mq4socket.cpp:3:10: fatal error: zmq.hpp: No such file or directory 3 | #include <zmq.hpp> | ^~~~~~~~~ compilation terminated.
已排查的内容
- zmq.hpp文件确实存在于路径
C:\ZeroMQ\include\cppzmq\zmq.hpp下 - tasks.json中的头文件包含路径和库路径看起来配置正确
- ZeroMQ库文件已放置在
C:\ZeroMQ\lib目录中
我的问题
- 如何解决编译时找不到zmq.hpp的错误?
- 我应该调整头文件的包含路径,还是修改代码中引入zmq.hpp的方式?
- 还有哪些配置项需要检查,才能确保编译器可以正确找到ZeroMQ的头文件和库文件?
相关代码片段(mq4socket.cpp)
#include <zmq.hpp>
当前重复确认的配置文件
tasks.json
{ "version": "2.0.0", "tasks": [ { "label": "Build DLL (Debug)", "type": "shell", "command": "g++", "args": [ "-shared", "-o", "output/mq4socket.dll", "mq4socket.cpp", "-I", "C:/ZeroMQ/include", "-L", "C:/ZeroMQ/lib", "-lzmq", "-g" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": ["$gcc"] }, { "label": "Build Test App (Debug)", "type": "shell", "command": "g++", "args": [ "-o", "output/test_app.exe", "test_app.cpp", "-I", "C:/ZeroMQ/include", "-L", "C:/ZeroMQ/lib", "-lzmq", "-g" ], "group": { "kind": "build", "isDefault": false }, "problemMatcher": ["$gcc"] } ] }
c_cpp_properties.json
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:/ZeroMQ/include" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "C:/mingw64/bin/g++.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64" } ], "version": 4 }
备注:内容来源于stack exchange,提问作者Hydra Corporation
相关产品推荐
相关产品推荐

