【问题标题】:'GLEWContext does not name a type' error on ubuntuubuntu 上的“GLEWContext 未命名类型”错误
【发布时间】:2016-06-11 11:28:52
【问题描述】:

我正在尝试将 glew_mx 项目从 windows 移植到 ubuntu,但由于 GLEWContext 未定义,我总是遇到错误。

error: ‘GLEWContext’ does not name a type

我知道我真的不需要在 linux 上使用 GLEWContext,但是我必须定义

GLEWContext* glewGetContext();

为了编译我的项目。所以我创建了一个全局 GLEWContext 并在 glewGetContext 中简单地返回它。
我的 window.h 代码如下所示:

#pragma once
#define GLEW_MX
#define GLEW_STATIC
#include "GL/glew.h"
#include "GLFW/glfw3.h"
#define GLM_SWIZZLE
#include "glm/glm.hpp"
#include "glm/ext.hpp"

#ifdef _WIN32
#define CONTEXT_PREFIX  window
#else
#define CONTEXT_PREFIX 
#endif

namespace window
{
    class Window
    {
    public:   
        Window() {}
        ~Window() {}

        //...

#ifdef _WIN32
        static void makeContextCurrent(Window* window_handle);
#endif
        static Window* createWindow(int win_width, int win_height, const std::string& title, GLFWmonitor* monitor, Window* share);

        GLFWwindow* window;
#ifdef _WIN32
        GLEWContext* glew_context;
#endif
        //...

    private:
        //...
    };

    GLEWContext* glewGetContext();
#ifdef _WIN32
    //...
#else
    GLEWContext* glew_context;
#endif
}

window.cpp 中的代码如下所示:

#ifdef _WIN32
GLEWContext* window::glewGetContext()
{
    //...
}
#else
GLEWContext* window::glewGetContext()
{
    return glew_context;
}
#endif

编译window.h最后两行时出现错误 非常感谢您的帮助

【问题讨论】:

    标签: c++ ubuntu opengl glew


    【解决方案1】:

    编译器似乎编译了您的Windowclass 并到达GLEWContext* glew_context 行。但是GLEWContext 可能没有定义,所以forward declaration 可能会有所帮助。

    由于您要从 Windows 移植到 ubuntu,因此您必须确保您的编译器支持 #pragma。您可以将包含防护更改为

    #ifndef WINDOW_H
    #define WINDOW_H
    // Your code here
    #endif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-01
      相关资源
      最近更新 更多