< stdlib.h>将MinGw包含目录添加到搜索路径时,在MinGW中找不到 [英] <stdlib.h> not found in MinGW when MinGw include directory is added to search path

查看:688
本文介绍了< stdlib.h>将MinGw包含目录添加到搜索路径时,在MinGW中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了错误

c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\cstdlib:75:25: fatal error: stdlib.h: No such file or directory
 #include_next <stdlib.h>

将C:\ MinGW \ include添加到编译器包含搜索路径时:
echo "#include <cstdlib>" | g++ -x c++ - -isystem C:/MinGW/include -o /dev/nul

when adding C:\MinGW\include to the compiler include search path:
echo "#include <cstdlib>" | g++ -x c++ - -isystem C:/MinGW/include -o /dev/nul

但是CMake这样做是因为某些库(例如libcurl)已安装到C:\ MinGW,因此curl include目录为C:\ MinGW \ include

But CMake does this because some libraries (libcurl e.g.) are installed into C:\MinGW hence the curl include dir is C:\MinGW\include

我做错什么了吗,或者这是MinGW中的错误吗? 我正在使用MinGW 5.0.1.

Am I doing something wrong or is this a bug in MinGW? I'm using MinGW 5.0.1.

有效方法:echo "#include <cstdlib>" | g++ -x c++ - -IC:/MinGW/include -o /dev/nul,但我不希望将curl include dirs等包含为非系统包含.

What works: echo "#include <cstdlib>" | g++ -x c++ - -IC:/MinGW/include -o /dev/nul but I don't want to include the curl include dirs etc. as non-system includes.

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

背景:我正在使用cmake生成makefile.因此,CMakelists.txt中有一个find_package(Curl)和一个include_directories(SYSTEM CURL_INCLUDE_DIRS).当libcurl安装到C:/MinGW时,CURL_INCLUDE_DIRS将为C:/MinGW/include,因此-isystem include.我不想省略SYSTEM,因为这可能会导致为libcurl标头生成警告.当然,还有更多库也以相同的方式安装,我想保持cmake文件的可移植性.

Background: I'm using cmake to generate the makefiles. So there is a find_package(Curl) and a include_directories(SYSTEM CURL_INCLUDE_DIRS) in the CMakelists.txt. As libcurl is installed to C:/MinGW the CURL_INCLUDE_DIRS will be C:/MinGW/include and hence the -isystem include. I don't want to omit the SYSTEM because this might cause warnings to be generated for the libcurl headers. Of course there are more libraries that are also installed in the same way and I want to keep the cmake files portable.

推荐答案

问题出在C ++标准头文件的include_next的使用上.根据 https://gcc.gnu.org/onlinedocs/cpp/Wrapper- Headers.html ,其中将包含标题searching the list of header file directories after the directory in which the current file was found.标准的包含目录(使用g++ -v)已得到(更正):

The problem lies in the use of include_next of the C++ standard header. According to https://gcc.gnu.org/onlinedocs/cpp/Wrapper-Headers.html it will include the header searching the list of header file directories after the directory in which the current file was found. The standard include directories (using g++ -v) are (corrected):

c:\ mingw \ lib/gcc/mingw32/6.3.0/include/c ++
c:\ mingw \ lib/gcc/mingw32/6.3.0/include/c ++/mingw32
c:\ mingw \ lib/gcc/mingw32/6.3.0/include/c ++/backward
c:\ mingw \ lib/gcc/mingw32/6.3.0/include
c:\ mingw \ include
c:\ mingw \ lib/gcc/mingw32/6.3.0/include-fixed
c:\ mingw \ mingw32/include

c:\mingw\lib/gcc/mingw32/6.3.0/include/c++
c:\mingw\lib/gcc/mingw32/6.3.0/include/c++/mingw32
c:\mingw\lib/gcc/mingw32/6.3.0/include/c++/backward
c:\mingw\lib/gcc/mingw32/6.3.0/include
c:\mingw\include
c:\mingw\lib/gcc/mingw32/6.3.0/include-fixed
c:\mingw\mingw32/include

因此,cstdlib将在c:\mingw\lib/gcc/mingw32/6.3.0/include/c++中找到,而include_next "stdlib.h"将在此列表的更下方并在c:\mingw\include中找到它.

Hence the cstdlib will be found in c:\mingw\lib/gcc/mingw32/6.3.0/include/c++ and include_next "stdlib.h" will go further down this list and will find it in c:\mingw\include.

现在出现问题:将库安装到C:\mingw中(使用库中的libbininclude文件夹)将使CMake在此处正确找到它们并将C:\mingw\include文件夹显式添加到包括清单.这两种情况的计算结果如下:

Now the problem: Installing the libraries into C:\mingw (using the lib, bin and include folders from the library) will make CMake correctly find them there and add the C:\mingw\include folder explicitly to the include list. The 2 cases work out as following:

  1. 添加为-I:g ++使用ignoring ... as it is a non-system directory that duplicates a system directory
  2. 会忽略此设置
  3. 添加为-isystem:这会将目录添加在上面的列表中,并将其作为重复项从其余目录中删除(已通过-v选项验证).这意味着当找到cstdlib并评估了include_next时,它将仅在列表的下方搜索.但是包含stdlib.h的目录不在列表中,而是在列表上方,因此没有进行搜索.因此出现错误.
    注意:我发现了include_next的另一个定义,该定义仅丢弃包含标题的目录.在这种情况下可以使用,但会导致循环,并已更改为所描述的行为.
  1. Adding as -I: This will be ignored by g++ with ignoring ... as it is a non-system directory that duplicates a system directory
  2. Adding as -isystem: This will prepend the directory to the list above and remove it from the rest as a duplicate (verified with the -v option). This means that when cstdlib is found and include_next is evaluated it will search only downward the list. But the directory containing the stdlib.h is not down the list anymore but upwards and therefore not searched. Hence the error.
    Note: I found another definition of include_next which only discards the directory containing the header. That would work in this case but can lead to loops and was changed to the described behaviour.

到目前为止,解决方案只是将库安装或复制到C:\mingw\mingw32.

Solution so far is simply installing or copying the libraries to C:\mingw\mingw32 instead.

这篇关于&lt; stdlib.h&gt;将MinGw包含目录添加到搜索路径时,在MinGW中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆