Eclipse Indigo C++ project settings

那年仲夏 提交于 2019-12-11 07:47:49

问题


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 ?


回答1:


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).



来源:https://stackoverflow.com/questions/9045298/eclipse-indigo-c-project-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!