[C/C++] cross platform coding

1. OS check

#if defined(_WIN32) || defined(_WIN64)
char* os = "windows";
#elif defined(__linux__)
char* os = "linux";
#elif defined(__APPLE__)
char* os = "osx";
#endif

2. Compiler Check

#if defined(_MSC_VER)
char* compiler = "msvc";
#elif defined(__GNUC__)
char* compiler = "gcc";
#elif defined(__clang__)
char* compiler = "clang";
#endif

3. C/C++ Check

#if defined(__cplusplus)
char* lang = "c++";
#else
char* lang = "c";
#endif

4. C++11 이상버전인지 확인

#if __cplusplus > 199711L || _MSC_VER > 160
const char* version = "support c++ 11";
#else
const char* version = "not support c++ 11";
#endif

C++의 갈라파고스 MSVC는 C++11을 완벽하게 지원하지 않아 __cplusplus 의 값이 199711 이다.
하지만 대부분의 자주 쓰는 C++11 기능은 사실 포함되어 있으므로 MSCV에서는 _MSC_VER 값을 보는것이 더 좋을듯 하다.


5. 프로세스 비트 확인(OS비트 아님)

#if defined(__x86_64__) || defined(__ppc64__) || defined(_WIN64)
const char* bit = "64";
#else
const char* bit = "32";
#endif

6. 컴파일러 위치

Visual Studio 2017

cl compiler : C:\Program Files (x86)\Microsoft Visual Studio\2017\$(VERSION)\VC\Auxiliary\Build\vcvarsall.bat
include path : C:\Program Files (x86)\Microsoft Visual Studio\2017\$(VERSION)\VC\Tools\MSVC\??.??.?????\include\
lib(x86) path : C:\Program Files (x86)\Microsoft Visual Studio\2017\$(VERSION)\VC\Tools\MSVC\??.??.?????\lib\x86
lib(x64) path : C:\Program Files (x86)\Microsoft Visual Studio\2017\$(VERSION)\VC\Tools\MSVC\??.??.?????\lib\x64

$(VERSION) 에는 Community,Enterprise,Professional 가 들어갈 수 있음.
??는 설치 버전번호 같은데, 매번 번호가 다르다.

Visual Studio 2015

cl compiler : C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/vcvarsall.bat
include path : C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/
lib(x86) path : C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/lib/
lib(x64) path : C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/lib/amd64/

Visual Studio 2013

cl compiler : C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/vcvarsall.bat
include path : C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/include/
lib(x86) path : C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/lib/
lib(x64) path : C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/lib/amd64/

Visual Studio 2012

cl compiler : C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/vcvarsall.bat
include path : C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/include/
lib(x86) path : C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/lib/
lib(x64) path : C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/lib/amd64/

Visual Studio 2010

cl compiler : C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/vcvarsall.bat
include path : C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include/
lib(x86) path : C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/lib/
lib(x64) path : C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/lib/amd64/

Windows GCC / G++

compiler : C:/MinGW/bin/gcc.exe , C:/MinGW/bin/g++.exe
include path : C:/MinGW/include
lib path : C:/MinGW/lib