【问题标题】:#include <netdb.h> in clion (with C) and working with threads#include <netdb.h> 在 clion 中(使用 C)并使用线程
【发布时间】:2022-01-25 00:45:16
【问题描述】:

我正在尝试包含:#include in clion with c。 这不承认包含,我该怎么办? 我是 clion 的新手,以前在 Visual Studio 工作过。

此外,我应该如何使用 clion 中的线程? 有什么我应该做的吗?

【问题讨论】:

标签: c clion


【解决方案1】:

您需要一组不同的 Windows 标头。您需要您的代码来调整差异:

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32)
/* Windows headers */
#include <windows.h>
#include <io.h>
#include <processthreadsapi.h>
#include <sysinfoapi.h>
#include <time.h>
#include <winsock2.h>

#else /* or check here for unix / linux & fail if OS unrecognized */
/* POSIX headers */
#include <netdb.h>
#include <poll.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/un.h>
#include <unistd.h>

#endif /* _WIN32 */

/* shared headers */
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

当然,您可能不需要我列出的所有标题,或者您可能需要其他标题,因此请根据需要调整代码。

此外,如果标题包含顺序在您的系统上不是问题,您可以将共享标题移到 if/else 块之外。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-19
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    相关资源
    最近更新 更多