mingw/include/c++/cstdlib: stdlib.h: 没有这样的文件或目录

mingw/include/c++/cstdlib: stdlib.h: No such file or directory

本文关键字:文件 c++ include cstdlib stdlib mingw      更新时间:2023-10-16

我正在尝试使用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。这是一个全新的安装,所以那里不应该有任何异常。

我解决了,我可以再次编译。

解决方案(对我来说(是添加变量CPLUS_INCLUDE_PATH的路径并将其设置为 MinGW c++ 包含目录,对我来说:C:MinGWlibgccmingw326.3.0includec++.

我希望它也对你有用。

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

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

此语法是在gcc6.0 中添加的,用于解决第三方库的问题。有关方法和推理,请参阅此处。

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