Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure my project to generate platform independent code?

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!

like image 395
samoz Avatar asked Jan 29 '26 08:01

samoz


2 Answers

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.

like image 73
PaV Avatar answered Jan 31 '26 00:01

PaV


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
like image 34
dmckee --- ex-moderator kitten Avatar answered Jan 31 '26 00:01

dmckee --- ex-moderator kitten