[英]Generate binaries using macros inside a source file
我试图通过在源文件中使用宏来生成输出文件。 无论宏名称是什么,使用宏名称生成最终的 .exe 文件。
#include <iostream>
#define Apple
//#define Banana
//#define Mango
int main()
{
...
}
我如何生成像 Apple.exe 这样的输出文件名?
编译器:g++ 操作系统:windows
您无法从源代码中控制最终链接器工件(在您的情况下可执行)的名称。
这需要使用-o <filename>
链接器标志来完成,因此在您的情况下
> g++ -o Banana.exe main.cpp -DNAME=Banana
为了更轻松地控制这一点,您可以将它们定义为 makefile 中的变量,例如
# Comment the current, and uncomment a different definiton to change the executables
# name and the macro definition for NAME
FINAL_NAME = Banana
# FINAL_NAME = Apple
# FINAL_NAME = Mango
$(FINAL_NAME).exe : main.cpp
g++ -o $(FINAL_NAME).exe main.cpp -DNAME=$(FINAL_NAME)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.