【问题标题】:Build Fail: winsock2.h file not found构建失败:未找到 winsock2.h 文件
【发布时间】:2012-03-08 19:22:13
【问题描述】:

添加了#define _WINSOCKAPI_,但构建仍然失败。

/*
 * $PostgreSQL: pgsql/src/include/port/win32/sys/socket.h,v 1.7 2006/10/04 00:30:10 momjian Exp $
 */
#ifndef WIN32_SYS_SOCKET_H
#define WIN32_SYS_SOCKET_H

/*
 * Unfortunately, <wingdi.h> of VC++ also defines ERROR.
 * To avoid the conflict, we include <windows.h> here and undefine ERROR
 * immediately.
 *
 * Note: Don't include <wingdi.h> directly.  It causes compile errors.
 */
#define _WINSOCKAPI_    //added this line but no help
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>

#undef ERROR
#undef small

/* Restore old ERROR value */
#ifdef PGERROR
#define ERROR PGERROR
#endif

/*
 * we can't use the windows gai_strerror{AW} functions because
 * they are defined inline in the MS header files. So we'll use our
 * own
 */
#undef gai_strerror

#endif   /* WIN32_SYS_SOCKET_H */

【问题讨论】:

    标签: objective-c xcode xcode4.2 file-not-found


    【解决方案1】:

    您正试图在绝对不是 Windows 的平台上编译特定于 Windows 的头文件。我无法想象你期望这会做什么;不管它是什么,它都不是。

    【讨论】:

    • 我正在尝试导入现有项目。
    • 所以不要把那个文件放在外面。另外:如果项目是 PostgreSQL,它打算从命令行构建,而不是从 XCode。
    【解决方案2】:

    尝试使用

    #ifndef __APPLE__ ... #endif

    然后,检查其他编译错误并包含苹果特定的套接字文件,这些文件也可以在 BSD 套接字下工作。

    【讨论】:

    • 上面的语句应该放在哪里?
    猜你喜欢
    • 2020-04-22
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 2022-11-01
    相关资源
    最近更新 更多