Is the solution widely used in Visual Studio?

I have a very large application created using Visual Studio 2008 that is designed to work on Windows XP. The code consists of a single solution file that contains six separate projects. My task is to port this application to Linux. I haven’t done anything before.

Yesterday, I discovered that my company wants this code to still compile on Windows as soon as I finish it. My first idea for this is to use a preprocessor instruction, for example:

#define COMPILE_FOR_LINUX

Then I could tell the compiler which files to include in the headers using preprocessor blocks such as:

#ifdef COMPILE_FOR_LINUX
// include required Linux headers here and skip Windows header includes
#else
// include required Windows headers here and skip Linux header includes
#endif

After including the appropriate files, I could encapsulate all the platform-dependent code with the following blocks:

#ifdef COMPILE_FOR_LINUX
// compile Linux specific code used here.
#else
// compile Windows specific code used here.
#endif

, COMPILE_FOR_LINUX, . , .

, , , Visual Studio, . Linux , COMPILE_FOR_LINUX, makefile . , , , , .

- - , ?

+5
1

, gcc , COMPILE_FOR_LINUX .

g++ -DCOMPILE_FOR_LINUX .....

, MSVS, Preprocessor directives ( , COMPILE_FOR_LINUX , COMPILE_FOR_WINDOWS ).

+3

All Articles