尝试运行已编译的 C++ 文件(使用 OpenGL)时出现问题。错误:“ld.so 检测到不一致:dl-version.c:224”

尝试运行已编译的 C++ 文件(使用 OpenGL)时出现问题。错误:“ld.so 检测到不一致:dl-version.c:224”

我在 cpp 中创建了一个简单的 opengl 文件。它可以在大学计算机上运行。我可以编译该文件,但无法运行编译后的文件。我得到的错误是:

Inconsistency detected by ld.so: dl-version.c: 224: _dl_check_map_versions: Assertion `needed != ((void *)0)' failed!

文件代码为:

    //
//  Model.cpp
//  cg-projects
//
//  Created by HUJI Computer Graphics course staff, 2013.
//

#include "ShaderIO.h"
#include "Model.h"

#include <GL/glew.h>
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#else
#include <GL/gl.h>
#endif

#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "glm/gtc/matrix_transform.hpp"

#define SHADERS_DIR "shaders/"

Model::Model() :
_vao(0), _vbo(0)
{

}

Model::~Model()
{
    if (_vao != 0)
        glDeleteVertexArrays(1, &_vao);
    if (_vbo != 0)
        glDeleteBuffers(1, &_vbo);
}

void Model::init()
{
    programManager::sharedInstance()
    .createProgram("default",
                   SHADERS_DIR "SimpleShader.vert",
                   SHADERS_DIR "SimpleShader.frag");

    GLuint program = programManager::sharedInstance().programWithID("default");

    // Obtain uniform variable handles:
    _fillColorUV  = glGetUniformLocation(program, "fillColor");

    // Initialize vertices buffer and transfer it to OpenGL
    {
        // For this example we create a single triangle:
        const float vertices[] = {
            0.75f, 0.75f, 0.0f, 1.0f,
            0.75f, -0.75f, 0.0f, 1.0f,
            -0.75f, -0.75f, 0.0f, 1.0f,
        };

        // Create and bind the object's Vertex Array Object:
        glGenVertexArrays(1, &_vao);
        glBindVertexArray(_vao);

        // Create and load vertex data into a Vertex Buffer Object:
        glGenBuffers(1, &_vbo);
        glBindBuffer(GL_ARRAY_BUFFER, _vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

        // Tells OpenGL that there is vertex data in this buffer object and what form that vertex data takes:

        // Obtain attribute handles:
        _posAttrib = glGetAttribLocation(program, "position");
        glEnableVertexAttribArray(_posAttrib);
        glVertexAttribPointer(_posAttrib, // attribute handle
                              4,          // number of scalars per vertex
                              GL_FLOAT,   // scalar type
                              GL_FALSE,
                              0,
                              0);

        // Unbind vertex array:
        glBindVertexArray(0);
    }
}

void Model::draw()
{
    // Set the program to be used in subsequent lines:
    GLuint program = programManager::sharedInstance().programWithID("default");
    glUseProgram(program);

    GLenum polygonMode = GL_LINE;   // Also try using GL_FILL and GL_POINT
    glPolygonMode(GL_FRONT_AND_BACK, polygonMode);

    // Set uniform variable with RGB values:
    float red = 0.3f; float green = 0.5f; float blue = 0.7f;
    glUniform4f(_fillColorUV, red, green, blue, 1.0);

    // Draw using the state stored in the Vertex Array object:
    glBindVertexArray(_vao);

    size_t numberOfVertices = 3;
    glDrawArrays(GL_TRIANGLES, 0, numberOfVertices);

    // Unbind the Vertex Array object
    glBindVertexArray(0);

    // Cleanup, not strictly necessary
    glUseProgram(0);
}

void Model::resize(int width, int height)
{
    _width  = width;
    _height = height;
    _offsetX = 0;
    _offsetY = 0;
}

我正在使用 ubuntu 13.10 谢谢 =]

答案1

我遇到了同样的问题,但代码要简单得多:

#include <string>
#include <GL/gl.h>
#include <GL/glut.h>

static void displayFunc(void){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
}

int main(int argc,char **argv){ 
    std::string nimportequoi;

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);

    if(glutCreateWindow("") == 0) return 1;

    glutDisplayFunc(displayFunc);
    glutMainLoop();
    return 0;
}

问题出在引入 std::string(我想任何与 C++ 相关的标准库对象都会这样做)与 GL(我尝试了一个没有 GL 的程序,它运行良好)时。如果我注释掉这一行,它就可以正常工作了!

相关内容