2016-04-01 26 views
0

:Eksik v-tablosu. Sebebi nedir? Ben aşağıdaki hatayı alıyorum neden görmek gibi olamaz

#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 

Şimdi bağlayıcı hatası bahsediyor .hpp dosyası için: Burada

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) 

ilgili koddur

#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 

Ve nihayet, uygulama

#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; 
} 

Garip bulduklarım, Mesh_Box_Line.cpp dosyasındaki sanal işlevlere ilişkin uygulamalara sahip olduğumu, yazımı ve her şeyi kontrol ettim.

Kaynakla ilgili herhangi bir fikir/eksiklerim neler?

+1

Tüm nesne dosyalarını bağlamanız gerekir. 'Mesh_Box_Line.o' ekleyemediniz. – harper

cevap

1

Sorun, Mesh_Box_Line.cpp dosyasının Xcode proje dosyasının yapı kurallarının bir parçası olmamasıydı. Bu hatayı alıyorsanız ve kodunuzun doğru olduğundan eminseniz, .cpp'nin ide'deki derlemenin bir parçası olduğundan emin olun.