Sign in to follow this  
jbizzler

Visual C++ 2 projects 1 solution mixing #ifdef statements

Recommended Posts

jbizzler    122
Hi. I'm using Visual C++ 2008 Express, and I have two projects in one solution that share source files. There are a few tiny differences in the code, though, so I thought I could easily fix them with #ifdef statements. But it's acting funny in a way I didn't expect. Each individual #ifdef statement is acting like it would in the project I last edited in, regardless of the project being compiled. To remedy this, I have to compile one project, tweak every #ifdef statement a tiny bit so it changes behavior, then compile the other project. This is probably some optimization feature to shorten compile times. Is there any proper way to fix this?

Share this post


Link to post
Share on other sites
Palidine    1315
you can set #defines as compiler arguments. i.e.


#ifdef PROJECT_A
//do something one way
#elif PROJECT_B
//do it another way
#endif




PROJECT_A and/or PROJECT_B are only #defined as compiler arguments (i.e. not in code). On visual studio you can find that in:

Solution properties -> Configuration Properties -> C/C++ -> Preprocessor. The field is named Preprocessor Definitions (at least on VS 2005)

So then on Project A you set PROJECT_A=1 and on Project B your set PROJECT_B=1

-me

Share this post


Link to post
Share on other sites
jbizzler    122
Yeah, that's what I'm doing. What I'm saying is, for some reason, if I last edited the #ifdef statement in PROJECT_A, and I compile both projects at the same time, PROJECT_B handles all those statements like it's PROJECT_A.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this