# Programmatically Enable/Disable Files for Compilation? [Resolved]

## Recommended Posts

Drew_Benton    1861
I was wondering if it is possible to programmatically enable/disable files for compilation. I took a look at MSDN through the compiler directives, but I could not find anything in particularly useful. I would assume this would be a Visual Studio 7 feature and not C++ specific. I am thinking that it is not possible, but maybe someone has done something like this before using some trick. I really do not want to make a whole bunch of separate project configurations, so I was looking for a possible shortcut if possible. Thanks! - Drew [Edited by - Drew_Benton on February 15, 2005 9:35:20 PM]

##### Share on other sites
mike25025    494
#ifdef USE_THIS_FILE
// file here
#endif

then add USE_THIS_FILE to the project defines when you want that file to compile

##### Share on other sites
Drew_Benton    1861
[lol] I feel so stupid now. Ok this is what I was aiming for:
In the project workspace, I have the .cpp files there. I wanted to enable/disable them, as you can do by right clicking and select exclude from build. I already had in my code:
#ifdef _LOG_	#include "logger.h"#endif

So I was thinking how can I now control the .cpp file? You just made me realize that I can do this, and get exactly what I needed.
#ifdef _LOG_	#include "logger.h"	#include "logger.cpp"#endif

*Sigh* A for the day for you and a rate++. Thanks! I really should get some sleep...being tired and programming simply do not mix well. Not only that I feel soo embarrassed. Saved me a lot of headaches [smile]

- Drew

[Edited by - Drew_Benton on February 15, 2005 9:33:22 PM]

##### Share on other sites
Oluseyi    2103
Might I recommend alternative file extensions? That way you can have all the files as part of your project all the time without fear of their being compiled (logger.cpp will be compiled as long as it is part of the project workspace).

##### Share on other sites
Drew_Benton    1861
Quote:
 Original post by OluseyiMight I recommend alternative file extensions? That way you can have all the files as part of your project all the time without fear of their being compiled (logger.cpp will be compiled as long as it is part of the project workspace).

[smile] Oluseyi, you are a genius! Thanks for that man. I was just debating how I could keep them with the project workspace. Much thanks as always for your helpfulness.

- Drew Benton

##### Share on other sites
Just to throw an extra alternative into the mix - it might be worth adding two extra configurations to your files debug_logged and release_logged which means that you can use your original approach of removing some files from the build process entirely.