Linux header 没有项目的 VS 文件

Linux header files in VS wihout project

我在 Windows 上使用 VS2019 编辑 C++ 代码文件。该代码适用于 Linux OS 并依赖于 headers,例如 #include visual studio 没有项目文件,所以我只能将其作为包含文件的目录打开。它确实知道包括 stdint.h 和 windows.h 但不包括 sys/socket.h.

如何设置VS知道标准Linuxheaders?以及如何在没有项目文件(我无法创建一个)的情况下为智能感知包含和任意文件。

我不打算构建任何东西只是为了使智能感知和代码完成成为可能。

Linux header files in VS wihout project

实际上<sys/socket.h>用于UNIX/Linux。而且Windows不能用

而不是,您应该在 Windows 上使用 <Winsock2.h>,它对应于 Linux 上的 socket.h。另外,不要忘记 link 对抗 Ws2_32.lib.

建议

使用这些:

#include<winsock2.h>
#pragma comment(lib, "Ws2_32.lib")

=====================

更新

我假设您的项目是 linux.

的 cmake

首先,你应该在vs installer中安装cmake的相关组件。参见 this document

然后,添加include_directories(${YOUR_DIRECTORY}) in cmakelist.txtfile to include the directory of thesocket.h`库。 See cmake project to include library directories.

在那之后,你可以在 cpp 文件中包含 header。