Finding What OS I'm Compiling On

Started by
6 comments, last by Uphoreum 16 years, 6 months ago
I'm hoping to be able to compile my framework on multiple platforms without any code change. Since it will be a DLL on Windows, I need to test whether to add "__declspec(dllexport)" based on what OS the framework is being compiled on. Is there a define in one of the standard headers that has what OS that the compiling is happening on? Or something like that? I'm hoping to do some #ifdef things to include/not include declspec.
Advertisement
Pre-defined C/C++ Compiler Macros.
Oh, I see. Thanks!
Okay, I looked in the SDL header to see what it did, and came up with this:

#if defined(__WIN32__)#define DECLSPEC __declspec(dllexport)#define DECLSPEC#endif#else


It acts as though __WIN32__ is not defined though, because the #define __declspec(dllexport) line is gray. I'm using Visual C++ 2005 Express. Is this the correct macro?
Quote:Original post by Uphoreum
It acts as though __WIN32__ is not defined though, because the #define __declspec(dllexport) line is gray. I'm using Visual C++ 2005 Express. Is this the correct macro?


The greyed out code feature of VS2005 doesn't work great. I found it only worked correctly about 50% of the time. Just turn it off.

Are you finding that the code isn't actually compiling correctly or are you just basing the "it's not working" off of what VS2005 is telling you with its font coloring?

-me
If you read the page I linked to you'd find that __WIN32__ is defined by Borland, which isn't MSVC 2005. Try _WIN32.
I think you want the "#else" between the two "#define"s:

#if defined(__WIN32__)#define DECLSPEC __declspec(dllexport)#else#define DECLSPEC#endif

Oops, sorry, I did a little copy/paste, but somehow pasted in the wrong place. That's why it was backwards.

Yep, _WIN32 worked. Sorry about not reading the page, I had seen __WIN32__ in the SDL headers earlier and decided that must be it, but it wasn't.

This topic is closed to new replies.

Advertisement