'GLEWContext does not name a type' ubuntu 错误
'GLEWContext does not name a type' error on ubuntu
我正在尝试将 glew_mx 项目从 windows 移植到 ubuntu,但由于未定义 GLEWContext,我总是会出错。
error: ‘GLEWContext’ does not name a type
我知道我真的不需要 linux 上的 GLEWContext 但是我必须定义
GLEWContext* glewGetContext();
为了编译我的项目。所以我创建了一个全局 GLEWContext 并在 glewGetContext 中简单地 return 它。
我的 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中的最后两行时出现错误
非常感谢您的帮助
编译器似乎编译了您的 Window
class 并到达了 GLEWContext* glew_context
行。但是 GLEWContext
可能没有定义,所以 forward declaration 可能会有帮助。
由于您要从 windows 移植到 ubuntu,因此您必须确保 #pragma
受您的编译器支持。您可以将包含保护更改为
#ifndef WINDOW_H
#define WINDOW_H
// Your code here
#endif
我正在尝试将 glew_mx 项目从 windows 移植到 ubuntu,但由于未定义 GLEWContext,我总是会出错。
error: ‘GLEWContext’ does not name a type
我知道我真的不需要 linux 上的 GLEWContext 但是我必须定义
GLEWContext* glewGetContext();
为了编译我的项目。所以我创建了一个全局 GLEWContext 并在 glewGetContext 中简单地 return 它。
我的 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中的最后两行时出现错误 非常感谢您的帮助
编译器似乎编译了您的 Window
class 并到达了 GLEWContext* glew_context
行。但是 GLEWContext
可能没有定义,所以 forward declaration 可能会有帮助。
由于您要从 windows 移植到 ubuntu,因此您必须确保 #pragma
受您的编译器支持。您可以将包含保护更改为
#ifndef WINDOW_H
#define WINDOW_H
// Your code here
#endif