Reputation: 61
I can't seem to see why I am getting the following error:
Undefined symbols for architecture x86_64:
"vtable for Mesh_Box_Line", referenced from:
Mesh_Box_Line::Mesh_Box_Line() in playground.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is the relevant code:
#ifndef MESH_HPP
#define MESH_HPP
class Mesh
{
public:
virtual void
init(const char* texturePath) = 0;
virtual void
render(const glm::mat4 & mvp) const = 0;
virtual void
cleanup() = 0;
};
#endif
Now for the .hpp file that the linker error is talking about
#ifndef MESH_BOX_LINE_HPP
#define MESH_BOX_LINE_HPP
#include <vector>
#include <cstring>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <GL/glew.h>
#include "Mesh.hpp"
// Note that this is the base mesh that all boxes will translate into their representations
class Mesh_Box_Line : public Mesh
{
public:
Mesh_Box_Line(){};
~Mesh_Box_Line(){};
void
init(const char* texturePath) override;
void
render(const glm::mat4 & mvp) const override;
void
cleanup() override;
private:
// static data for out base mesh
static const GLfloat g_position_buffer_data[];
static const GLfloat g_color_buffer_data[];
// static data for base mesh again
// Globals for our buffer and shader ID
GLuint PositionBufferID; // gl generated vert buffer id
GLuint UVBufferID; // gl generated UV texture coord id
GLuint TextureID; // gl generated Texture id
GLuint ProgramID; // gl generated shader program id
GLuint mvpID; // uniform mvp
};
#endif
And finally, the implementation
#include "Mesh_Box_Line.hpp"
#include "texture.hpp"
#include "shader.hpp"
const GLfloat Mesh_Box_Line::g_position_buffer_data[] = {
-1.0f,-1.0f,-1.0f, // line 01
+1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f, // line 02
-1.0f,+1.0f,-1.0f,
-1.0f,-1.0f,-1.0f, // line 03
-1.0f,-1.0f,+1.0f,
-1.0f,+1.0f,+1.0f, // line 04
+1.0f,+1.0f,+1.0f,
-1.0f,+1.0f,+1.0f, // line 05
-1.0f,-1.0f,+1.0f,
-1.0f,+1.0f,+1.0f, // line 06
-1.0f,+1.0f,-1.0f,
+1.0f,-1.0f,+1.0f, // line 07
-1.0f,-1.0f,+1.0f,
+1.0f,-1.0f,+1.0f, // line 08
+1.0f,+1.0f,+1.0f,
+1.0f,-1.0f,+1.0f, // line 09
+1.0f,-1.0f,-1.0f,
+1.0f,+1.0f,-1.0f, // line 10
-1.0f,+1.0f,-1.0f,
+1.0f,+1.0f,-1.0f, // line 11
+1.0f,-1.0f,-1.0f,
+1.0f,+1.0f,-1.0f, // line 12
+1.0f,+1.0f,+1.0f,
};
const GLfloat Mesh_Box_Line::g_color_buffer_data[] = {
+0.0f,+1.0f,+1.0f, // line 01
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 02
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 03
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 04
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 05
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 06
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 07
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 08
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 09
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 10
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 11
+0.0f,+1.0f,+1.0f,
+0.0f,+1.0f,+1.0f,// line 12
+0.0f,+1.0f,+1.0f,
};
void
Mesh_Box_Line::init(const char* texturePath)
{
// Generate Buffers
glGenBuffers(1, &PositionBufferID); // gl generated vert buffer id
glGenBuffers(1, &UVBufferID); // gl generated UV texture coord id
// Initialize & generate textures
//TextureID = loadDDS(texturePath);
// Load and initialize shaders
ProgramID = LoadShaders("Simple_VS.glsl", "Simple_FS.glsl"); // gl generated shader program id
//UniformID = glGetUniformLocation(UniformID, <var-name-in-shader>);
glGetUniformLocation(ProgramID, "mvp");
}
void
Mesh_Box_Line::render(const glm::mat4 & mvp) const
{
// BIND SHADER
glUseProgram(ProgramID);
// BIND UNIFORM DATA
glUniformMatrix4fv(mvpID, 1, GL_FALSE, &mvp[0][0]);
// BIND TEXTURE
// glActiveTexture(GL_TEXTURE0);
// glBindTexture(GL_TEXTURE_2D, TextureID);
// BIND POSITION BUFFER
//glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, this->PositionBufferID);
glBufferData(GL_ARRAY_BUFFER,
sizeof(Mesh_Box_Line::g_position_buffer_data_lines),
&Mesh_Box_Line::g_position_buffer_data_lines[0],
GL_STATIC_DRAW );
// BIND COLOR BUFFER
//glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, UVBufferID);
glBufferData(GL_ARRAY_BUFFER,
sizeof(Mesh_Box_Line::g_color_buffer_data_lines),
&Mesh_Box_Line::g_color_buffer_data_lines[0],
GL_STATIC_DRAW );
// now for the drawing
//Vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, this->PositionBufferID);
glVertexAttribPointer(0,
3,
GL_FLOAT,
GL_FALSE,
0,
(void*) 0 );
// color
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, this->UVBufferID);
glVertexAttribPointer(1,
3,
GL_FLOAT,
GL_FALSE,
0,
(void*) 0 );
// gl settings
// gl blend function
// draw call
glDrawArrays(GL_LINES, 0, 12*2 );
// Now, disable bound arrays
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
// disable anything enabled
return;
}
void
Mesh_Box_Line::cleanup()
{
// Delete buffers
glDeleteBuffers(1, &PositionBufferID);
glDeleteBuffers(1, &UVBufferID);
// Delete Texture
glDeleteTextures(1, &TextureID);
// Delete Shader
glDeleteProgram(ProgramID);
return;
}
What I find strange is that I do have implementations of the virtual functions in the file Mesh_Box_Line.cpp, I have checked the spelling and everything.
Any ideas on the source/what I'm missing?
Upvotes: 0
Views: 138
Reputation: 61
The issue was that the Mesh_Box_Line.cpp was not a part of the build rules for the Xcode project file. If you are getting this error and you are sure your code is correct make sure that the .cpp are a part of the build in your ide.
Upvotes: 1