2015-10-06 223 views
2

我沿着教程以下在線,我知道我在做一個很初級語法錯誤的地方,但相較於2010年給了我非常模糊的描述上的錯誤,我已經在我的主要程序測試了這些功能,他們的工作,但由於某種原因,呼籲從我的主,這些類的功能時,我不斷收到error LNK2019: unresolved external symbol "public: __thiscallVS 2010 C++錯誤LNK2019:無法解析的外部符號「公用:__thiscall

我的頭文件:

#ifndef SHADER_H 
#define SHADER_H 

#include <string> 
#include <fstream> 
#include <sstream> 
#include <iostream> 

#include <glew.h>; // Include glew to get all the required OpenGL headers 

class Shader 
{ 
public: 

    GLuint Program; 

    Shader(const GLchar* vertexPath, const GLchar* fragmentPath); 

    void Use(); 
}; 

#endif 

我的cpp文件:

#pragma once 
#ifndef SHADER_H 
#define SHADER_H 

#include <string> 
#include <fstream> 
#include <sstream> 
#include <iostream> 
#include "Shader.h" 
#include <glew.h> 
#include "Shader.h" 

class Shader 
{ 
public: 
    GLuint Program; 

//I've tried Shader(const GLchar* vertexPath, const GLchar* fragmentPath) 
//instead of Shader::Shader 

Shader::Shader(const GLchar* vertexPath, const GLchar* fragmentPath) 
    { 
     //generates shader 
    } 

    // Uses the current shader 
void Shader::Use() 
    { 
    glUseProgram(this->Program); 
    } 
}; 

#endif 

錯誤來這裏: Main.cpp的

#include <iostream> 
    #include <string> 
    #include <fstream> 
    #include <sstream> 
    #include <iostream> 
    #include <glew.h> 
    //#define GLEW_STATIC 
    // GLFW 
    #include <glfw3.h> 
    // Other includes 
    #include "Shader.h" 


    int main() 
    { 

    Shader ourShader("shader.vs","shader.fs"); <-- Error here 

    // Game loop 
    while (!glfwWindowShouldClose(window)) 
    { 

    // Draw the triangle 
    OurShader.Use(); <-- Error here 

    } 
+0

請檢查下面給出的答案,謝謝。 –

回答

1

只要你有閱讀一些基本的C++教程或參考書。

  • 需要* .cpp文件無標題的畢業生
  • 沒有必要在* .cpp文件中再次定義類
  • 所有包括* .h文件中的文件是在* .cpp文件提供
  • Becaue SHADER_H限定在頭文件。你的* .cpp文件不包括在內編譯

你的代碼應該是這樣的。我沒有構建代碼。但只是想一想結構。

聽文件

#ifndef SHADER_H 
#define SHADER_H 

#include <string> 
#include <fstream> 
#include <sstream> 
#include <iostream> 
#include <glew.h> 

class Shader 
{ 
public: 
    GLuint Program; 
    Shader(const GLchar* vertexPath, const GLchar* fragmentPath); 
    void Use(); 
}; 

#endif 

CPP文件

#include "Shader.h" 

Shader::Shader(const GLchar* vertexPath, const GLchar* fragmentPath) 
{ 
    //generates shader 
} 
void Shader::Use() 
{ 
    glUseProgram(this->Program); 
} 

主要

int main() 
{ 
    Shader ourShader("shader.vs", "shader.fs"); 
    while (!glfwWindowShouldClose(window)) 
    {  
     OurShader.Use(); 
    } 
} 
+0

它的工作原理,謝謝。我完全刪除了這些頭文件和類文件。 – user3452887

相關問題