【问题标题】:Can't Access sys/socket.h using Cygwin无法使用 Cygwin 访问 sys/socket.h
【发布时间】:2013-03-10 19:41:55
【问题描述】:

我需要在安装了 MicGW GCC 和 G++ 4.7 的 Windows 8 中编译 C/C++ pthread 和套接字代码。 当我使用g++ test.cpp -o test编译我的测试代码时

代码是:

#include<iostream>
#include<sys/socket.h>
#include<sys/types.h>
using namespace std;

int main() {
     cout<<"Got Socket";
}

这会产生错误fatal error: sys/socket.h not foundtypes.h 也一样

我发现的错误是 cygwin 使用的是 MicGW GCC 和 g++,但我希望它使用自己的而不是 MinGW 的,以便我可以包含 Linux 库。

【问题讨论】:

    标签: linux gcc g++ cygwin mingw


    【解决方案1】:

    我无法在我的 Cygwin 上重现您的问题。

    头文件是否存在于 /usr/include/sys 中?

    【讨论】:

    • 是的。但是我观察到它没有使用 /usr/include/sys 中存在的头文件使用库来编译 cpp/c 文件?但它使用 C:\MinGW\include\c++\4.7.0 的头文件这样做
    • 也许它没有使用正确的编译器?试试“which g++”看看它使用的是哪一个。您还可以使用 -I 参数指定包含路径。
    【解决方案2】:

    [installed directory]/usr/include 中搜索sys 文件夹,如果socket.h 不存在,则下载一个手动复制到那里。

    不怕手工 ;-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-15
      • 2011-02-26
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2015-12-21
      • 2015-12-12
      相关资源
      最近更新 更多