我正试图通过在源文件中使用宏来生成输出文件。无论宏名称是什么,都要使用宏名称生成最终的.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)