2016-06-11 2 views
1

glew_mxプロジェクトをWindowsからubuntuに移植しようとしていますが、GLEWContextが定義されていないためにエラーが発生します。私は私は本当にいけないことを知っている'GLEWContextはubuntuでタイプを指定しません'

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 で最後の2行をコンパイル中にエラーが発生しましたあなたの助けに多くのお礼

答えて

1

コンパイラはあなたのWindowクラスをコンパイルし、GLEWContext* glew_context行になるようです。しかし、GLEWContextは定義されていない可能性がありますので、forward declarationが役に立ちます。

Windowsからubuntuに移植しているので、#pragmaがコンパイラによってサポートされていることを確認する必要があります。インクルードガードを変更することができます

#ifndef WINDOW_H 
#define WINDOW_H 
// Your code here 
#endif 
関連する問題