windows 是否有独立的 C++ 源预处理器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1645538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:21:16  来源:igfitidea点击:

Is there a standalone C++ source preprocessor?

c++windowsc-preprocessor

提问by Geo

Is there a standalone C++ preprocessor? I don't need the compiler/linker, and I'm not able to install a full kit.

是否有独立的 C++ 预处理器?我不需要编译器/链接器,也无法安装完整的工具包。

I'd like to be able to obtain preprocessed version of some headers, using some defines and include paths I provide.

我希望能够使用我提供的一些定义和包含路径来获取某些标头的预处理版本。

EDIT: I can't rely on anything being available. No cl, no gcc, nothing. The least I would need done is something that processes macros ( specifically #ifdef and #if ).

编辑:我不能依赖任何可用的东西。没有cl,没有gcc,什么都没有。我至少需要做的是处理宏(特别是 #ifdef 和 #if )。

EDIT: I'm using this on a Windows XP computer.

编辑:我在 Windows XP 计算机上使用它。

回答by Geo

cpp is what you're looking for. I am not sure if it can be gotten outside of gcc distribution, though

cpp 就是你要找的。我不确定它是否可以在 gcc 发行版之外获得,但

CPP(1)                                                                 GNU                                                                 CPP(1)

NAME
       cpp - The C Preprocessor

SYNOPSIS
       cpp [-Dmacro[=defn]...] [-Umacro]
           [-Idir...] [-Wwarn...]
           [-M|-MM] [-MG] [-MF filename]
           [-MP] [-MQ target...]
           [-MT target...]
           [-P] [-fno-working-directory]
           [-x language] [-std=standard]
           infile outfile

Only the most useful options are listed here; see below for the remainder.

DESCRIPTION
       The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform your program before
       compilation.  It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs.

回答by Jerry Coffin

You might want to look at Boost Wave. It's a preprocessor built as a library instead of an application, but putting a wrapper around it to turn it into a standalone program should be fairly trivial (most of what you'd do is connect things up so it knows what file(s) to read from and write to).

你可能想看看Boost Wave。它是一个作为库而不是应用程序构建的预处理器,但是在它周围放置一个包装器以将它变成一个独立的程序应该是相当简单的(您要做的大部分事情就是将事物连接起来,以便它知道要使用哪些文件)读取和写入)。

回答by Graphics Noob

You may want to have a look at GPP, Generic Pre Processor. It's customizable but it looks like it comes with some predefined setting which will do C/C++ preprocessing.

您可能想看看GPP,通用预处理器。它是可定制的,但看起来它带有一些预定义的设置,可以进行 C/C++ 预处理。

Edit: Looks like -C is the setting to use

编辑:看起来 -C 是要使用的设置

-C cpp compatibility mode. This is the mode where gpp's behavior is the closest to that of >cpp. Unlike in the default mode, meta-macro expansion occurs only at the beginning of >lines, and C comments and strings are understood.

-C cpp 兼容模式。这是 gpp 的行为与 >cpp 的行为最接近的模式。与默认模式不同,元宏扩展只发生在 > 行的开头,并且可以理解 C 注释和字符串。

回答by Aftershock

http://mcpp.sourceforge.net/

http://mcpp.sourceforge.net/

mpp portable c preprocessor:

mpp 便携式 C 预处理器:

mcpp project was selected as one of the year 2002 "Exploratory Software Projects" at Information-Technology Promotion Agency, Japan (IPA), and selected again for the year 2003 projects. For the achievements of the project, the author was evaluated as one of the highest class programmers<<

mcpp 项目被日本信息技术振兴机构 (IPA) 选为 2002 年度“探索性软件项目”之一,并再次入选 2003 年度项目。对于项目的成就,作者被评为最高级程序员之一<<

回答by zildjohn01

Many compilers have a command-line option that will do what you want.

许多编译器都有一个命令行选项可以执行您想要的操作。

For example, GCC's is -E, and MSVC's is /P.

例如,GCC 是-E,MSVC 是/P

回答by Don Wakefield

I suppose you could tryto build your own app using the standalone library, cpplib, but while they supply it, they don't recommend using it that way as it "has not yet reached a point of reasonable stability." I don't know how long that has been true.

我想您可以尝试使用独立库cpplib构建自己的应用程序,但是虽然他们提供了它,但他们不建议以这种方式使用它,因为它“尚未达到合理的稳定性点”。我不知道这已经多久了。

回答by Jonathan Leffler

Usually, the C++ compiler provides you with an option to see the preprocessed source.

通常,C++ 编译器会为您提供查看预处理源代码的选项。

With GCC, as was commented, you use:

正如评论的那样,使用 GCC,您可以使用:

g++ -E ...other options... files

On some systems, especially Unix systems, there may be a separate 'cpp' program. On MacOS X it installed as /usr/bin/cpp and is part of the GCC (GNU Compiler Collection).

在某些系统上,尤其是 Unix 系统上,可能有一个单独的“cpp”程序。在 MacOS X 上,它安装为 /usr/bin/cpp 并且是 GCC(GNU Compiler Collection)的一部分。

Sometimes, it is installed in more out of the way places - on Solaris 10, it is /usr/lib/cpp, for example.

有时,它安装在更偏僻的地方 - 例如,在 Solaris 10 上,它是 /usr/lib/cpp。