【问题标题】:mingw/include/c++/cstdlib: stdlib.h: No such file or directorymingw/include/c++/cstdlib:stdlib.h:没有这样的文件或目录
【发布时间】:2017-07-21 20:06:06
【问题描述】:

我正在尝试使用 MinGW 在 Fedora 26 上为 64 位 Windows 交叉编译 OpenImageIO。在使用yum 检索依赖项的mingw 版本后,我运行mingw64-cmake,然后运行make。但是,我马上收到一个关于找不到 stdlib.h 的编译错误。

[  0%] Built target CopyFiles
[  0%] Building CXX object src/libutil/CMakeFiles/OpenImageIO_Util.dir/argparse.cpp.obj
In file included from .../oiio/src/libutil/argparse.cpp:36:0:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
              ^~~~~~~~~~
compilation terminated.

我已确认至少在/usr/include//usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/ 中找到了stdlib.h,而给出编译器错误的文件也位于该位置。

为什么我仍然收到错误stdlib.h: No such file or directory

更新: 我做了额外的研究并了解到以下内容:The preprocessor directive #include_next behaves like the #include directive, except that it specifically excludes the directory of the including file from the paths to be searched for the named file.

这可以解释为什么cstdlib 无法从同一文件夹中找到stdlib.h。但是cstdlib 是 MinGW 的一部分,而不是我试图编译的代码的任何部分。所以我仍然不知道这里出了什么问题或如何解决这个错误。

编辑:这是编译器版本信息,以防万一:https://pastebin.com/PZiXS2fg。这是一个全新的安装,所以应该不会有任何异常。

【问题讨论】:

  • 出于好奇,您的mingw64 中包含哪个g++ 版本?
  • @TriskalJM gcc 版本 7.1.0 20170502 (Fedora MinGW 7.1.0-1.fc26)
  • 您的/usr/x86_64-w64-mingw32/sys-root/mingw/include/ 中没有stdlib.h 会被#include_next 找到吗?
  • 听起来很糟糕。如果你只编译#include &lt;cstdlib&gt;g++ -c,或者只编译#include &lt;stdlib.h&gt;gcc -c,它会找到它吗?
  • @ssbsa 我也想知道。但是,从CMakeFile 中删除-isystem 似乎可以解决问题。之后我遇到的新错误只是通过消除oiio/src/include/OpenImageIO/missing_math.h 中不必要的 Win32 特定定义来解决。现在没有更多的错误,它似乎可以编译。感谢您的提示!仍然需要弄清楚-isystem 的来源以及如何解决这个问题,而不必在 cmake 之后直接编辑 CMakeFiles,这可以变成答案。

标签: c++ gcc cmake mingw fedora


【解决方案1】:

我解决了,我可以重新编译。

解决方案(对我而言)是将变量 CPLUS_INCLUDE_PATH 添加到路径并将其设置为 MinGW c++ 包含目录,对我而言:C:\MinGW\lib\gcc\mingw32\6.3.0\include\c++

我希望它也对你有用。

【讨论】:

  • 为我工作!还得重启电脑。
【解决方案2】:

根据我的谷歌搜索,#include_next 的使用似乎会导致很多问题。尝试使用以下语法直接包含stdlib.h

-isystem /usr/x86_64-w64-ming32/sys-root/mingw/include/c++

gcc 6.0 中添加了此语法,以解决第三方库的问题。方法和推理见here

编辑:更改答案以反映有关 gcc wrapper_headers 和#include_next的新信息

【讨论】:

  • 这些是 GCC 配置标志。您是否建议重新编译 GCC?
  • 我尝试运行:mingw64-cmake -DCMAKE_CXX_FLAGS='--with-gxx-include-dir=/usr/x86_64-w64-mingw32/sys-root/mingw/include/c++ --enable-version-specific-runtime-libs' 但我收到:unrecognized command line option '--with-gxx-include...'
  • @TriskalJM 我添加了-isystem /usr/x86_64-w64-ming32/sys-root/mingw/include/c++ flag,通过make -n 确认g++ 确实在使用该标志运行,并确认stdlib.h 在该目录中。但是,仍然会出现完全相同的错误。
  • 您提到了两个包含stdlib.h 版本的目录。 g++ 拉入的是哪个版本?
  • @TriskalJM g++ 参数如下:pastebin.com/LHcqqAkr。完整的 g++ 版本信息在这里pastebin.com/PZiXS2fg。我有默认的--includedir=/usr/include,这是stdlib.h 的另一个版本所在的位置。我全新安装了 Fedora 26 和最新版本的软件包,没有做任何会导致问题的更改。
猜你喜欢
  • 2010-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-15
  • 2015-02-26
相关资源
最近更新 更多