本文介绍了动态变量cpp编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望自编译以来,我可以在.h文件中编辑变量。
I wish I could edit a variable in a .h file since compilation Example:
#include <iostream> #include <stdlib.h> #define HOST (char *)"localhost/" #define PATH "insert"我要像这样从编译中编辑 HOST :
I want to edite HOST from compilation like this:
g++ -o output source.cpp -HOST mywebsite/推荐答案
您可以使用以下方法轻松地做到这一点:
You can easily do that with something like this:
#include <iostream> #include <stdlib.h> #ifndef HOST #define HOST (char*)"localhost/" #endif #define PATH "insert"然后,在命令行上,您指定'-DHOST = (char *)随便什么'(它将被使用),或者不传递任何 -DHOST = 标志和默认标志
Then, on the command-line, you either specify '-DHOST=(char*)"whatever"' (and it will be used), or do not pass in any -DHOST= flag, and the default in the header will be used.
更多推荐
动态变量cpp编译
发布评论