How can I do this in c++/Eclipse CDT ?
我怎样才能在c ++ / Eclipse CDT中做到这一点?
#if BUILD = DEBUG
#define DB_FILE="DB"
#elif BUILD = RELEASE
#define DB_FILE="/home/project/clientXY.DB"
....
Is there any configuration option in CDT that I can modify between the builds (to change the above parameters)?
我可以在构建之间修改CDT中的任何配置选项(更改上述参数)吗?
many thanks in advance :D
非常感谢提前:D
2 个解决方案
#1
If you go into the Project Properties dialog, select C/C++ General - Paths and Symbols and select the Symbols tab, you can set symbols which act as if you'd #defined them in the code.
如果进入“项目属性”对话框,选择“C / C ++常规 - 路径和符号”并选择“符号”选项卡,可以设置符号,就像在代码中#defined它们一样。
As there's a selector for "Configuration" above it, I imagine you can have >1 configuration with different symbols, although I haven't tried that. Also I don't use the symbols in the actual build process, I just use them to help with the visibility of sections that are under conditional configuration.
由于上面有一个“配置”选择器,我想你可以有> 1配置不同的符号,虽然我没有尝试过。此外,我不使用实际构建过程中的符号,我只是使用它们来帮助条件配置下的部分的可见性。
I hope this is helpful, though.
不过,我希望这会有所帮助。
#2
i found the answer in the propeties of the project, if you want somekind of preprocessor process different between Debug and Release or any other, the only thing you have to do is:
我在项目的属性中找到了答案,如果你想在Debug和Release之间或其他任何一些预处理程序进程不同,你唯一需要做的就是:
- Properties of the project
- C/C++ Build
- Settings
- Tool Settings
- if you're working with C++ "GCC C++ Compiler" if you are not "GCC C Compiler"
- Preprocessor
- Under Defined Sumbols(-D) "Add..."
- there you write something like "XXX_BUILD" ,what i wrote "BUILD_RELEASE"
- Apply and OK
项目的属性
如果您使用的是C ++“GCC C ++编译器”,如果您不是“GCC C编译器”
在Defined Sumbols下(-D)“Add ...”
在那里你写了类似“XXX_BUILD”的内容,我写的是“BUILD_RELEASE”
申请并确定
remember to do this in both builds configuration.
记得在两个构建配置中都这样做。
then in your code ( in my case in a header) you add the following
然后在你的代码中(在我的情况下在标题中)添加以下内容
#ifdef XXX_BUILD
//something
#include "someHeaderThatOnlyWorkOnXXX_BUILD.h"
#elif YYY_BUILD
//something else
#include "someWhereElseThatWorksOnYYY_BUILD.h"
#endif
#1
If you go into the Project Properties dialog, select C/C++ General - Paths and Symbols and select the Symbols tab, you can set symbols which act as if you'd #defined them in the code.
如果进入“项目属性”对话框,选择“C / C ++常规 - 路径和符号”并选择“符号”选项卡,可以设置符号,就像在代码中#defined它们一样。
As there's a selector for "Configuration" above it, I imagine you can have >1 configuration with different symbols, although I haven't tried that. Also I don't use the symbols in the actual build process, I just use them to help with the visibility of sections that are under conditional configuration.
由于上面有一个“配置”选择器,我想你可以有> 1配置不同的符号,虽然我没有尝试过。此外,我不使用实际构建过程中的符号,我只是使用它们来帮助条件配置下的部分的可见性。
I hope this is helpful, though.
不过,我希望这会有所帮助。
#2
i found the answer in the propeties of the project, if you want somekind of preprocessor process different between Debug and Release or any other, the only thing you have to do is:
我在项目的属性中找到了答案,如果你想在Debug和Release之间或其他任何一些预处理程序进程不同,你唯一需要做的就是:
- Properties of the project
- C/C++ Build
- Settings
- Tool Settings
- if you're working with C++ "GCC C++ Compiler" if you are not "GCC C Compiler"
- Preprocessor
- Under Defined Sumbols(-D) "Add..."
- there you write something like "XXX_BUILD" ,what i wrote "BUILD_RELEASE"
- Apply and OK
项目的属性
如果您使用的是C ++“GCC C ++编译器”,如果您不是“GCC C编译器”
在Defined Sumbols下(-D)“Add ...”
在那里你写了类似“XXX_BUILD”的内容,我写的是“BUILD_RELEASE”
申请并确定
remember to do this in both builds configuration.
记得在两个构建配置中都这样做。
then in your code ( in my case in a header) you add the following
然后在你的代码中(在我的情况下在标题中)添加以下内容
#ifdef XXX_BUILD
//something
#include "someHeaderThatOnlyWorkOnXXX_BUILD.h"
#elif YYY_BUILD
//something else
#include "someWhereElseThatWorksOnYYY_BUILD.h"
#endif