【问题标题】:OpenGL redefinition error while compiling glm conflict with Windows SDK files编译 glm 时 OpenGL 重新定义错误与 Windows SDK 文件冲突
【发布时间】:2012-10-22 11:32:46
【问题描述】:

当我将一个模块(使用OpenGLglm)(作为单个程序测试和编译OK)添加到一个大程序中时。项目中编译glm时出现错误:

1>d:\program files (x86)\microsoft visual studio 9.0\vc\include\glm\core\type_gentype.hpp(48) : error C2332: “class”: missing tag name
1>d:\program files (x86)\microsoft visual studio 9.0\vc\include\glm\core\type_gentype.hpp(48) : error C2011: “<unnamed-tag>”: “enum” type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\shlobj.h(3599) : see declaration of '<unnamed-tag>'

我搜索了谷歌,在here 发现了类似的问题。回答说是头文件序列有问题,但是不知道怎么解决。

代码在type_gentype.hpp,代码在glm

namespace glm
{
    enum profile
    {
        nice,
        fast,
        simd
    };

namespace detail
{
    template
    <
        typename VALTYPE, 
        template <typename> class TYPE   //**The error indicator pointing at here**
    >
    struct genType
    {
    public:
        enum ctor{null};

        typedef VALTYPE value_type;
        typedef VALTYPE & value_reference;
        typedef VALTYPE * value_pointer;
        typedef VALTYPE const * value_const_pointer;
        typedef TYPE<bool> bool_type;

        typedef sizeType size_type;
        static bool is_vector();
        static bool is_matrix();

        typedef TYPE<VALTYPE> type;
        typedef TYPE<VALTYPE> * pointer;
        typedef TYPE<VALTYPE> const * const_pointer;
        typedef TYPE<VALTYPE> const * const const_pointer_const;
        typedef TYPE<VALTYPE> * const pointer_const;
        typedef TYPE<VALTYPE> & reference;
        typedef TYPE<VALTYPE> const & const_reference;
        typedef TYPE<VALTYPE> const & param_type;

        //////////////////////////////////////
        // Address (Implementation details)

        value_const_pointer value_address() const{return value_pointer(this);}
        value_pointer value_address(){return value_pointer(this);}

    //protected:
    //  enum kind
    //  {
    //      GEN_TYPE,
    //      VEC_TYPE,
    //      MAT_TYPE
    //  };

    //  typedef typename TYPE::kind kind;
    };

    template
    <
        typename VALTYPE, 
        template <typename> class TYPE
    >
    bool genType<VALTYPE, TYPE>::is_vector()
    {
        return true;
    }

c:\program files\microsoft sdks\windows\v6.0a\include\shlobj.h(3599)enum的重定义部分

enum
{   // **The error indicator pointing at here**
    BMICON_LARGE = 0,
    BMICON_SMALL
};

#undef  INTERFACE
#define INTERFACE   IBanneredBar
// the rest of the shlobj.h file

【问题讨论】:

  • 能否提供出现问题的代码?也许忘记了分号,或者在拆分成单独文件的过程中重复了一些东西?
  • @RandolphCarter 我添加了错误指示器指向的代码
  • 不应该是template &lt;typename blah&gt; class TYPE(你缺少模板参数名称)
  • 和 BMICON_LARGE 听起来像是来自 windows 的预定义常量;如果您绝对需要使用该名称重新声明枚举值,请将其放入单独的命名空间
  • 问题已解决。在大程序中,有人使用#define short TYPEtype_gentype.hpp 中的TYPE 冲突

标签: c++ windows opengl redefinition


【解决方案1】:

关于 BMICON_LARGE,这听起来好像已经有该名称的预定义常量/枚举值。最好的解决方案是简单地使用不同的名称。如果您绝对需要该确切名称,请将其放入您自己的命名空间;或者你可以使用已经定义的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多