How can I configure my project to create platform-independent code?

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

This is due to the lack of Windows strcasecmp. I read a little about how I can create some kind of header for my code, but I do not understand this concept very well. I worked on the code on my Mac using only vim and make, but now I'm trying to switch it to Visual Studio.

Is there a way when I can set up my project to include the titles of the Windows browser when I build on Windows, but omit them when I create my box for Mac or Linux?

This problem really gives me a headache, and I will be grateful for any suggestions!

+3
source share
4 answers

You could do

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

There is also a MS Visual Studio macro: _MSC_VER, therefore

#ifdef _MSC_VER

will also work here.

There is also a WINVER define in windows.h.

+7
source

set up my project to create platform independent code

This is a bit of a weird phase, so I'm not sure I'm answering the right question, but it says here:

You need to write platform independent code.

Perform one of the following actions:

  • Writing to a cross-platform structure (i.e. QT)
  • Use only library functions available for all your purposes.

or

  • provide wrappers to fill in any gaps in the library for purposes (or more)
+1
source

Boost libraries are designed for cross-platform work. In particular, if you need to manipulate strings, you will probably find what you need. And it will be cross-platform, without having to deal with it yourself. See there for an idea of ​​what is available.

+1
source

perhaps you might consider compiling your code with MINGW32 in windows.

0
source

Source: https://habr.com/ru/post/1710442/


All Articles