user3452887
user3452887

Reputation: 83

VS 2010 C++ error LNK2019: unresolved external symbol "public: __thiscall

I am following along a tutorial online and I know I'm making a very beginners Syntax mistake somewhere but VS 2010 gives me very vague descriptions on the errors, I've tested these functions in my main program and they work but for some reason I keep getting error LNK2019: unresolved external symbol "public: __thiscallwhen calling these class functions from my main.

My header file:

#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

my Cpp file:

#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

Error comes here : 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

    }

Upvotes: 2

Views: 401

Answers (1)

Nayana Adassuriya
Nayana Adassuriya

Reputation: 24766

Simply you have to read some basic C++ tutorial or reference book.

  • No header grads needed for *.cpp files
  • No need to define class again in *.cpp file
  • All the include files in *.h file is available in *.cpp file
  • Becaue SHADER_H define in header file. your *.cpp file not included for compile

You code should be something like this. I didn't build the code. But just take an idea about the structure.

Hear file

#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 file

#include "Shader.h"

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

main

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

Upvotes: 1

Related Questions