DavidColson
DavidColson

Reputation: 8587

Glm VECTORIZE2_VEC redefined XCode warning

I keep getting warnings only in XCode about some macros in glm being redefined. it's not a huge issue but I find warnings annoying.

If I put a #ifndef block over the culprit macros but then the entire system wont work? I include them in a static lib which is linked to an app which also includes them. I though this might be the issue so I removed it from one of the two to see if it helped. It didn't.

This warning does not appear when using mingw g++ on windows but it does in Xcode 4. I am using glm version 0.9.3.4.

Warnings:

"VECTORIZE2_VEC" redefined
This is the location of the previous definition

This is repeated hundreds of times.

Culprit code (taken from glm file _vectorize.hpp):

#define VECTORIZE2_VEC(func) \
template <typename T> \
GLM_FUNC_QUALIFIER detail::tvec2<T> func( \
    detail::tvec2<T> const & v) \
{ \
    return detail::tvec2<T>( \
        func(v.x), \
        func(v.y)); \
}

There are a few other macros very similar to this one.

Upvotes: 0

Views: 180

Answers (1)

Brady
Brady

Reputation: 10357

Based on the comments above, it appears as though you have 3 options:

  1. Just live with the compilation warnings

  2. Change the location of your VECTORIZE2_VEC macro definition with respect to the #include's, since the other definition of VECTORIZE2_VEC has not wrapped it in an #ifndef (and this is causing the compilation warning)

  3. Consider if you really need to #define it again, considering its already defined.

Option 1 is ok, but if you have a "no compilation warning" requirement, which is actually a good thing, then you'll have to go with option 2 (which in my opinion could become difficult to maintain) or 3.

To implement option 2, you will need to define the macro after the include where it is originally defined, but before the other #include's that need it. This may not be possible, if you get the original definition and the compilation error by just #including one file, in which case you're out of luck.

Assuming file1.h has the original VECTORIZE2_VEC definition, and file2.h needs the definition and causes a compilation error in its absence, the following could fix the problem and be error and warning free:

#include <file1.h>

#ifdef VECTORIZE2_VEC 
  #undef VECTORIZE2_VEC 
#endif
#define VECTORIZE2_VEC(func) ....

#include <file2.h>

// ...

Upvotes: 1

Related Questions