Sign in to follow this  

preprocessor defines, for entire solution (VC++ 7.1)

This topic is 4548 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

Multiple projects in the same solution; many of the projects are used in other solutions, which require different pre-defined macros to compile correctly. Q: Is there a way to define macros (such as the _WIN32 macro) for an entire solution in VC++ 7.1? Looked at the documentation; tried to figure it out intuitively... seems you have to define each macro on a project-by-project basis. Sure would be handy to not have to remove/add macros to each project when changing solutions. Would also rather not put anything in a .h file, since much of the base code is common to all projects--and inserting an early .h file (with the defined macros) would affect all solutions. Thanks Chad

Share this post


Link to post
Share on other sites
Maybe you could create a .h containing the macros (hear me out on this :p) but surround the definition of said macros with an #ifdef for the solution's name. For example, if you've got a solution named "Salt Water" and another named "Copper Sulphate":


/* macros.h */

#ifdef SOLUTION_COPPERSULPHATE

/* "Copper"-Specific Macros here */
/* They will not apply to "Copper Sulphate" */

#endif

#ifdef SOLUTION_SALTWATER

/* "Salt Water"-Specific Macros here */
/* They will not apply to "Copper Sulphate" */

#endif

#ifdef SOLUTION_SHARED

/* Shared Macros here */
/* Only used if SOLUTION_SHARED is defined */

#endif



It is a bit of a kludge and would require some nesting, but this way, you only need to define SOLUTION_{NAME} on a per-solution basis and add the necessary #ifdef, rather than each macro. Any solution for which you don't need the macros, you simply don't put an ifdef in for or define SOLUTION_SHARED.

Ok, that's actually a completely god-awful mess looking back on it, but it might help.

Share this post


Link to post
Share on other sites
there is a way to do preprocessor defines from the project settings. But this is mainly for just defining variables like _CONSOLE or _DEBUG, etc. I just messed around to see if I could define a regular macro, it is possible, but not worth it because it doesn't let you use commas, so if you were trying to do a macro with a function call it wouldn't work...

Share this post


Link to post
Share on other sites
Quote:
Original post by moeron
there is a way to do preprocessor defines from the project settings. But this is mainly for just defining variables like _CONSOLE or _DEBUG, etc. I just messed around to see if I could define a regular macro, it is possible, but not worth it because it doesn't let you use commas, so if you were trying to do a macro with a function call it wouldn't work...


Actually you can create a macro that makes a function call quite easily. In VS.NET solution preferences you can do:

"MACRO_NAME=function(param1, param2)"

By including the quotes the entire definition is passed to the compiler as a single argument. I don't believe that you can use this to declare a macro that ACCEPTS parameters though but since I've never had the need to do that I've never tried.

The MSDN is your friend! :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Helter Skelter
Actually you can create a macro that makes a function call quite easily. In VS.NET solution preferences you can do:

"MACRO_NAME=function(param1, param2)"

By including the quotes the entire definition is passed to the compiler as a single argument. I don't believe that you can use this to declare a macro that ACCEPTS parameters though but since I've never had the need to do that I've never tried.

The MSDN is your friend! :)


Nice =) Only needed to add quotes, learn something new everyday.

Share this post


Link to post
Share on other sites
Yup. SO it doesn't work for solutions :( MSDN is not your friend [crying]

[wink]

Thanks for the suggestions on the kludge, Motz... but we'll probably just have to define the macros in the project settings and change them each time we change solutions... or create duplicate projects or something.

Share this post


Link to post
Share on other sites

This topic is 4548 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.

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