为什么我不能导入头文件库中的我的头文件中的一个?(Why can't I import he

2019-09-28 13:08发布

我使用的是C ++ socket.io库在我的C ++项目,我无法包括在我的项目所需要的头文件的头文件。

但是,当我包括我的CPP文件所需的头文件,我能够成功地包括所需的头文件。

采取措施,利用库:

  1. 编译C ++ websocketpp,OpenSSL的,Boost库,并准备JSON库。
  2. 链接反对我的VS2015项目中的* .lib文件。
  3. 包括在C的头文件位置++额外包括依赖关系文件夹。
  4. 包含在链接的* .lib文件的位置包括依赖关系文件夹。
  5. 包括我的CPP文件中的三个头文件。
  6. 建立。 好极了! 有用!
  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. 循环依赖? 也许我通过在我的类的头文件导致循环依赖,以及其他头文件中的一个,包括相同的文件。

Answer 1:

解:

我想通了,发生问题是什么是。 无论是Socket.io C ++库,并在问候词Qt的份额命名空间“发出”。 在别人运行到这个问题,这里的事件是怎么解决它:

  1. 混帐克隆https://github.com/raksa/SocketIO-cpp-lib
  2. 编辑术语的所有情况下“发射”的源文件。 在我的情况我他们全部改为“emit_signal”。
  3. 在websocketpp库中的git结帐发展。 (会不会在编译主站或从最近的标签为2017年2月16日)。
  4. 重新编译从调试和释放SocketIO-CPP-lib的项目sioclient.lib文件。
  5. 转到您的项目和反对的lib文件链接。 此外,提供的lib文件路径。
  6. 包括sioclient.h,siosocket.h和siomessage.h文件的目录include路径。
  7. 包括Boost库路径和Boost库* .lib文件到您的项目。
  8. 包括任何Socket.io C ++头文件在你的项目时,不应有错误。

希望这可以帮助别人有同样的问题。

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



文章来源: Why can't I import header files to a library in one of my header files?
标签: c++ socket.io