在c++中剥离编译源代码的任何脚本
Any script to strip out the compiled source in C++
在我的c++文件中,我有
#ifdef DEBUG
then blah
#else
blooh.
我想去掉预处理后没有编译的所有文本,这样如果DEBUG
没有定义,那么所有形式的语句:
#ifdef DBUG
/* some debug code */
#endif
被从源文件中剥离。
编辑:下面是一个例子:
#include <iostream>
//#define DEBUG
int main(){
#ifdef DEBUG
cout << "In debugn";
#endif
cout << "hellon";
return 0;
}
运行脚本后,输出应为
#include <iostream>
//#define DEBUG
int main(){
cout << "hellon";
return 0;
}
仅仅运行预处理器还不够好吗?例如:g++ -E
?
用适当的定义运行编译器的预处理器。在Windows上,这将是cl /EP file
,在Linux上是gcc -E
。最有可能的是,您也必须传递您的定义,使用-DFoo
.
我不知道你问题的答案,但谷歌知道:
- C的部分预处理器
- cpp-partial——预处理器指令部分求值器
预处理器执行此操作。
您可以使用g++ -E somefile.cpp
查看它生成的内容
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何通过cpp程序运行shell脚本
- 如何在不产生任何垃圾的情况下获得C中的像素
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- 在程序中编写脚本来编写和编译代码
- C++映射有2个键,这样任何1个键都可以用来获取值
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- RtlCaptureStackBackTrace未捕获任何帧
- 如何在c++中使用system()来运行包含空格的python脚本
- 在cygwin中运行c++脚本时发生错误
- 链表c++插入,所有情况都已检查,但没有任何工作
- 如何将真正的字符串从python c-api转换为python脚本
- C++模板函数,用于比较任何无符号整数和有符号整数
- 用于将C++代码转换为 Web 程序集的脚本未终止
- 如何使用C++初始化向量;脚本化值不是数组、指针或矢量错误
- 使用C++或任何windows脚本语言格式化文本数据
- 如何将串行数据从Python脚本发送到Windows上的Arduino - 没有任何效果
- 在c++中剥离编译源代码的任何脚本
- GDB Python脚本:通过C/C++结构字段迭代的任何示例