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

This topic is 3792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
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 on other sites
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 on other sites
Make sure that the IDE actually recompiles the code.

##### Share on other sites
Ah, yes. They were sharing an "Intermediate Directory" so the code was not being compiled independently between projects. Thanks!

1. 1
Rutin
26
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 10
• 10
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002086
×