2015-10-06 230 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

相关问题