简体   繁体   中英

Build with different values in c++ Eclipse CDT

How can I do this in 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)?

many thanks in advance :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.

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.

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:

  1. Properties of the project
  2. C/C++ Build
  3. Settings
  4. Tool Settings
  5. if you're working with C++ "GCC C++ Compiler" if you are not "GCC C Compiler"
  6. Preprocessor
  7. Under Defined Sumbols(-D) "Add..."
  8. there you write something like "XXX_BUILD" ,what i wrote "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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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