views:

180

answers:

4

I am writing an application that I would like to release binaries for on Mac, Windows, and Linux. I have code that compiles under Mac and Linux, but under Windows, it does not.

This is because of Windows lack of a strcasecmp. I've read a little bit about how I can create some sort of header to wrap my code, but I don't really understand this concept too well. I've worked on the code on my Mac with just vim and make, but now I'm trying to switch it all over to Visual Studio.

Is there some way I can set my project up to include Windows wrapper headers when I'm building on Windows, but omit them when I'm building on my Mac or Linux box?

This problem is really giving me a headache and I'd appreciate any suggestions!

+7  A: 

You could do

#ifdef WIN32
#include <windows_specific_header.h>
#else
#include <other_header.h>

There is also an MS Visual Studio-specific macro: _MSC_VER, so

#ifdef _MSC_VER

would also work here.

There is also WINVER define in windows.h.

PaV
Is WIN32 a compiler defined symbol or is that something I have to define?
samoz
This is a compiler-defined symbol.
PaV
You have to be a bit careful with WIN32, since it's sometimes true in compilers that you think aren't Windows-y. IIRC for instance it's true when compiling Symbian code for the emulator, even though no Windows headers or libraries are available. Doesn't affect you if your platforms are just win/linux/mac, but might matter to code designed to be extremely portable.
Steve Jessop
Does WIN32 appear in Netbeans under windows?
samoz
+1  A: 

configure my project to generate platform independent code

That is a bit of an odd phase, so I'm not sure that I'm aswering the right question, but here goes:

You have to write platform independent code.

Do one of these:

  • Write to a cross-platform framework (i.e. QT)
  • Only use library functions that are available on all your targets

or

  • provide wrappers to fill up any gaps in the library for on (or more) targets
dmckee
Well mostly I need some string functions that Windows doesn't provide. Rather, they provide them, but under a different name, so a Windows compiler won't find the same functions that Mac or Linux would.
samoz
+1  A: 

Boost libraries are designed to be cross-platform. In particular, if you need to manipulate strings, you'll probably find what you need. And it will be cross-platform without having to deal with it yourself. See there to get a glimpse of what's available.

Benoît
A: 

maybe you can consider compiling your code with MINGW32 on windows.

bill