'GLEWContext does not name a type' Ubuntu 上的错误

'GLEWContext does not name a type' error on ubuntu

本文关键字:Ubuntu 错误 type name GLEWContext does not      更新时间:2023-10-16

我正在尝试将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
}

窗口中的代码.cpp如下所示:

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

窗口中编译最后两行时发生错误。非常感谢您的帮助

编译器似乎编译了您的Window类并进入GLEWContext* glew_context行。但GLEWContext可能未定义,因此前向声明可能会有所帮助。

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

#ifndef WINDOW_H
#define WINDOW_H
// Your code here
#endif
相关文章: