include_next预处理程序指令导致MSVC中出现问题 [英] include_next preprocessor directive causing problems in MSVC

查看:552
本文介绍了include_next预处理程序指令导致MSVC中出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道inlcude_next恰好是C预处理程序的GNU扩展. 我在使用MSVC编译Gnu库代码时遇到问题.例如,有一个stdio.h头文件或GNU-like <stdio.h>.使用MS编译器进行编译时,我得到invalid preprocessor command 'include_next'很好,因为没有类似Windows的#include_next指令.进行#include_next的主要目的是要在项目中创建一个名为stdio.h的文件,该文件将被包含在内,而不是默认头文件.

I know that inlcude_next happens to be GNU extension of the C preprocessor. I am facing an issue compiling Gnu library code using MSVC. For instance, there is an stdio.h header file or rather GNU-like <stdio.h>. When compiled using MS compiler, I get invalid preprocessor command 'include_next' which is fine because there is nothing like a #include_next directive for windows. The main aim of doing #include_next being you would like to create a file called stdio.h in your project, and that would be included instead of the default header.

因此,我尝试了2种选择: 1)在所有文件中将此行// #include_next <stdio.h>注释掉. 2)或用#include <stdio.h>替换#include_next.

So, I tried 2 options: 1) Comment out this line // #include_next <stdio.h> in all the files. 2) Or replace #include_next by #include <stdio.h>.

我不知道选择1)是否会引起任何问题(最后出现链接器错误). 关于2),我得到了fatal error C1014: too many include files : depth = 1024也很好.为此,我将wrapper #ifndef用作 include guards # pragma once指令.

I don't know if opting for 1) will cause any problems(linker errors at the end). Regarding 2), I got fatal error C1014: too many include files : depth = 1024 which is also fine. For this, I would use wrapper #ifndef for the include guards or # pragma once directive.

以下是我的担忧:

我是否需要在头文件stdio.h内编写类似#include <stdio>#include "stdio.h"的语句?为Windows编译时是否有意义?我仅在需要的所有源文件中直接执行#include "stdio.h"就够了,这样它就可以绕过Visual C标准头文件而使用我的吗? 而且,如果我完全省略语句include_next,可能会/可能不会发生?

Do I need to write a statement like #include <stdio> or #include "stdio.h"inside the header file stdio.h? Will it make any sense when compiling for Windows. Won't I suffice with just doing #include "stdio.h" directly in all the source files where it needs, so that it would bypass the Visual C standard header and rather use mine? And, what might/might not happen if I omit the statement include_next in entirety?

我的主要目标是使用MSVC成功编译gnu库. 如果我遗漏了一些东西,或者可能对这个话题有更多的了解,请纠正我.

My main aim being to successfully compile gnu libraries using MSVC. Please correct me if I am missing something or perhaps throw more light on this topic.

推荐答案

选项1和2都不起作用.它是一个将系统包裹起来的头文件.因此,如果您将其注释掉,则系统头文件将不包含在内,并且其定义也将丢失.而且,如果将其更改为普通#include,它将再次包含相同的标头,从而导致无限循环.

Neither option 1 nor 2 are going to work. It is a header that wraps the system one. So if you comment it out, the system header won't get included and it's definitions will be missing. And if you change it to plain #include, it will include the same header again, causing infinite loop.

提高使用率

#include <../include/stdio.h>

这在WinNT上有效,因为所有标准标头都在名为include的目录中.它也可以在标准WinCE SDK上使用,但是不幸的是,并非在所有这些上都可以使用.

this works on WinNT, because all the standard headers happen to be in directories called include. It also works on standard WinCE SDKs, but unfortunately does not work on all of them.

这篇关于include_next预处理程序指令导致MSVC中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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