[CMake] Eclipse generator - basic macros

Mike Jackson mike.jackson at bluequartz.net
Wed Jul 15 11:21:38 EDT 2009


On Wed, Jul 15, 2009 at 2:18 AM, Hendrik Sattler<post at hendrik-sattler.de> wrote:
> Zitat von Benjamin Schindler <bschindler at inf.ethz.ch>:
>>
>> I'm working on a project which builds both on linux and windows. I
>> generated an eclipse project out of it which works basically fine but
>> it's not able to recognize i.e. the __GNUC__ macro (and probably any
>> other macro defined per default on gcc) are not recognized by eclipse.
>> That means that by using a header like:
>>
>> #if defined(_MSC_VER) && (_MSC_VER >= 1300)
>> #ifdef FLOW_DLL_EXPORT
>> #define FLOW_DLL _declspec(dllexport)
>> #else
>> #define FLOW_DLL _declspec(dllimport)
>> #endif
>> #else
>> #ifdef __GNUC__
>> #define FLOW_DLL
>> #endif
>> #endif
>
> I know that it's unrelated to your question but this code is slightly wrong.
> For the windows version of gcc, it also understands the _declspec() thing.
> You don't make it compiler-specific but system-specific.
> Additionally, on non-windows systems, you can use the visibility attribute
> to achieve something similar.
> That's why the gcc people suggest the following at
> http://gcc.gnu.org/wiki/Visibility (I simplified it):
> #if defined _WIN32 || defined __CYGWIN__
>  #ifdef FLOW_DLL_EXPORT
>    #define FLOW_DLL __declspec(dllexport)
>  #else
>    #define FLOW_DLL __declspec(dllimport)
>  #endif
> #elif __GNUC__ >= 4
>  #define FLOW_DLL __attribute__ ((visibility("default")))
>  #define DLL_LOCAL  __attribute__ ((visibility("hidden")))
> #endif
> #ifndef FLOW_DLL
> #define FLOW_DLL
> #endif
> #ifndef DLL_LOCAL
> #define DLL_LOCAL
> #endif
>
> You only need to add -fvisibility=hidden to gcc command line on non-windows
> systems.
> The above still has the flaw you use _declspec(dllimport) when compiling the
> library as static library. That's ok if you don't intend to do so else easy
> to fix.
>
> Additionally, eclipse may not select the right choice but the macros will
> not error out as they are _always_ defined in some way.
>
> Have fun
>
> HS

I think I need some explanation on this logic.

This line:

#if defined _WIN32 || defined __CYGWIN__

will always be true on msvc, mingw and cygwin because _WIN32 is
defined for the MS compilers and when MinGW is being used so the
"#elif" will _never_ get executed? Where am I going wrong on this?

I put the following at the top of a source file and compiled with
MinGW and got an error:

#ifdef _WIN32
#error Um what is wrong
#endif

 I looked at the GCC page cited above and I think it would have the
same problem.

Mike


-- 
Mike Jackson                               mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net


More information about the CMake mailing list