I created a C++ shared library project in Ubuntu with compiler g++ 4.6.
Some of the dependency libraries expects some preprocessor commands about compiler and operating system to properly compile, like
#elif defined(__GNUC__) || defined(__llvm__) || defined(__clang__)
However Eclipse doesn't define them automatically (at least the version I'm using), is there a setting or option in Eclipse which does this for me ?
You can set preprocessor defines in the project properties: .
However, in your case, I wouldn't use these, as they shouldn't be project specific (due to them being compiler specific). I actually think you're looking for these. I'm not sure for llvm/clang (there are ones, but I don't remember them right now), but for GCC you should use the macro __GNUC__
which will be defined by the compiler itself, without you having to worry about it. The leading underscores tell you, that they aren't part of the standard and not necessarily defined when using another compiler (e.g. MSVC).
For cross platform usage of vsprintf_s
:
// this will be set on Visual Studio only, so this code is added for all other compilers
#ifndef _MSC_VER
#define vsprintf_s(b,l,f,v) vsprintf(b,f,v);
#endif
But in general, try to use functions that are available on all platforms (for this example, in this case use vsnprintf()
instead).