简体   繁体   English

在c ++ Eclipse CDT中使用不同的值进行构建

[英]Build with different values in c++ Eclipse CDT

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

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 ++常规-路径和符号”,然后选择“符号”选项卡,则可以设置符号,就像在代码中#define一样。

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. 由于上面有一个用于“配置”的选择器,我想您可以使用不同的符号进行> 1个配置,尽管我没有尝试过。 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. 另外,我不在实际的构建过程中使用这些符号,我只是使用它们来帮助了解条件配置下各节的可见性。

I hope this is helpful, though. 我希望这会有所帮助。

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或任何其他版本不同的预处理器进程,那么您唯一要做的就是:

  1. Properties of the project 项目属性
  2. C/C++ Build C / C ++构建
  3. Settings 设定值
  4. Tool Settings 工具设定
  5. if you're working with C++ "GCC C++ Compiler" if you are not "GCC C Compiler" 如果您使用的是C ++“ GCC C ++编译器”,如果您不是“ GCC C编译器”,
  6. Preprocessor 预处理器
  7. Under Defined Sumbols(-D) "Add..." 在定义的汇总(-D)下,“添加...”
  8. there you write something like "XXX_BUILD" ,what i wrote "BUILD_RELEASE" 在那里,您写的是“ XXX_BUILD”,我写的是“ BUILD_RELEASE”
  9. Apply and OK 申请并确定

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM