gpt4 book ai didi

c++ - 为什么我不能将头文件导入到我的某个头文件中的库中?

转载 作者:行者123 更新时间:2023-11-30 05:17:08 24 4
gpt4 key购买 nike

我正在使用 C++ socket.io library在我的 C++ 项目中,我无法在我的项目头文件中包含所需的头文件。

但是当我在我的 CPP 文件中包含所需的头文件时,我能够成功地包含所需的头文件。

使用库的步骤:

  1. 编译C++ websocketpp、openssl、boost库,准备JSON库。
  2. 链接到我的 VS2015 项目中的 *.lib 文件。
  3. 在 C++ 附加包含依赖项文件夹中包含头文件位置。
  4. 在链接器包含依赖项文件夹中包含 *.lib 文件位置。
  5. 在我的 CPP 文件中包含三个头文件。
  6. build 。耶!有用!
  7. 尝试将库功能封装到我自己的类/对象中。
  8. 尝试在我的头文件中包含三个库头文件。请注意有关初始化的大量编译错误。

头文件导入

#include <sio_message.h>
#include <sio_socket.h>
#include <sio_client.h>

在头文件中包含头文件时出错:

Severity    Code    Description Project File    Line    Suppression State
Error C2440 'initializing': cannot convert from 'nullptr' to 'const int &' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'function<void __cdecl(sio::message::list const &)>': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'function<void __cdecl(sio::message::list const &)>': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2440 'initializing': cannot convert from 'nullptr' to 'const int &' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'list': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'list': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2439 'sio::socket::ack': member could not be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2439 'sio::socket::ack': member could not be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2439 'sio::socket::msglist': member could not be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2439 'sio::socket::msglist': member could not be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2530 'sio::socket::name': references must be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 96
Error C2530 'sio::socket::name': references must be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 96
Error C2838 'string': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'string': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2059 syntax error: ')' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2059 syntax error: ')' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2143 syntax error: missing ')' before 'const' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2143 syntax error: missing ')' before 'const' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2143 syntax error: missing ';' before 'const' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2143 syntax error: missing ';' before 'const' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75

可能的问题:

  1. 共享命名空间?也许我传播的命名空间不正确?
  2. 循环依赖?也许我通过在我的类中包含头文件而导致循环依赖,而其他头文件之一包含同一个文件。

最佳答案

解决方案:

我弄清楚了问题出在哪里。 Socket.io C++ 库和 Qt 都共享关于“emit”这个词的命名空间。如果其他人遇到这个问题,我就是这样解决的:

  1. git 克隆 https://github.com/raksa/SocketIO-cpp-lib
  2. 编辑源文件中术语“emit”的所有实例。就我而言,我将它们全部更改为“emit_signal”。
  3. websocketpp 库中的 git checkout 开发。 (不会在 master 上或从 2017 年 2 月 16 日的最新标签编译)。
  4. 从 SocketIO-cpp-lib 项目重新编译 sioclient.lib 文件以进行调试和发布。
  5. 转到您的项目并链接到 lib 文件。另外,提供 lib 文件路径。
  6. 将 sioclient.h、siosocket.h 和 siomessage.h 文件的目录包含到您的包含路径中。
  7. 将 boost 库路径和 boost 库 *.lib 文件包含到您的项目中。
  8. 在项目中包含任何 Socket.io C++ 头文件时不应出现错误。

希望这对遇到同样问题的其他人有所帮助。

注意:我在构建 sioclient.lib 文件时还遇到了另一个问题。您可能需要在其中一个项目文件夹中创建一个“优化”和“调试”文件夹。 CMAKE 脚本错误地引用了项目中不存在的文件夹。或者从 CMAKE 脚本中删除这些行。

关于c++ - 为什么我不能将头文件导入到我的某个头文件中的库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42262291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com