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

Started by
3 comments, last by jbizzler 16 years, 1 month ago
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?
Advertisement
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
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.
Make sure that the IDE actually recompiles the code.
Ah, yes. They were sharing an "Intermediate Directory" so the code was not being compiled independently between projects. Thanks!

This topic is closed to new replies.

Advertisement