Jump to content
  • Advertisement
Sign in to follow this  
jchmack

detecting compiler subsystem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

im using VS2005 SP1 and I frequently switch my console on and off and right now i have to go to the project properties and have to change the linker properties and the value of #if in the following code:

#if 1
int main(int argc, char *argv[])
#else
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )

#endif
{

    MY MAIN STUFF HERE

    return 0;
}




my question is, is there a way i can just have the compiler detect what subsystem im using like: #if 1 -> #if SOMETHING so that i dont have to change this value each time?

Share this post


Link to post
Share on other sites
Advertisement
yes.

Use #ifdef _CONSOLE, and define _CONSOLE in your project properties.

project properties // C/C++ // Preprocessor // Preprocessor definitions

or don't define it for a windowed app. You can then create different project configurations for console/windowed if you want.

Share this post


Link to post
Share on other sites
Quote:
Original post by mrbastard
yes.

Use #ifdef _CONSOLE, and define _CONSOLE in your project properties.

project properties // C/C++ // Preprocessor // Preprocessor definitions

or don't define it for a windowed app. You can then create different project configurations for console/windowed if you want.


i apologize im not to familiar with doing stuff like this. Im not exactly sure what you mean... I tried doing this:


if _CONSOLE
int main(int argc, char *argv[])
#else
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )





but _CONSOLE always evaluates to true so i can only run console apps.

Im switching my properties by going to:
properties//linker//system//subsystem
and switchign between windows/console

could you please elaborate for a preprocessor newbie like myself. Maybe with some example code?

Share this post


Link to post
Share on other sites
You should usually not change between console and windows applications this way. As mrbastard said, it is preferable to create two configurations, set one configuration to console and define _CONSOLE, then set the other configuration to windows.

Then, change between the configurations.

Share this post


Link to post
Share on other sites
I think you're after something more like



#ifdef _CONSOLE

int main(int argc, char *argv[])

#else

#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )

#endif





you don't want to check the value of _CONSOLE, you want to check if it's been defined.

BTW I rely on SDL to wrap the main() signature for me, so I'm not sure if the winapi bit is correct or not, sorry.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
You should usually not change between console and windows applications this way. As mrbastard said, it is preferable to create two configurations, set one configuration to console and define _CONSOLE, then set the other configuration to windows.

Then, change between the configurations.


well i dont really want to have multiple configurations i just want it to generate one .exe. Im not too familiar with making new configurations i just use the default debug/release and mostly not even debug. I would like it to just detect what kind of subsystem i have during compile time some how. But i think ill learn to make a new configuration.

Share this post


Link to post
Share on other sites
Quote:
Original post by jchmack
well i dont really want to have multiple configurations i just want it to generate one .exe.


It actually works out easier to have multiple configs. It saves you forgetting to change the subsystem back after testing, and means rather than going through all the property pages to change it you can just select the proper configuration and hit build.

It means you can have your console exe and your windowed exe in different folders so you easily know which is which without rebuilding. If you don't need one of them at a given time, then don't build that configuration.

This is probably more important for large solutions with multiple projects though, so do whatever works for you.

Share this post


Link to post
Share on other sites
yeah my initial fear was that it would take up alot of space because of media files but i can just generate the .exe in the same folder.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!