本文介绍了运行已编译的C ++文件(使用OpenGL)时出错.错误:"ld.so检测到不一致:dl-version.c:224"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created a simple opengl file in cpp. It works on the University computer. I'm able to compile the file, but i can not run the compiled file. The error I get is:

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.

i'm using ubuntu 13.10.

推荐答案

Ubuntu 13.10的某些更新似乎已更改了某些内容.我也已经编译并运行了没有问题的代码,仅仅有一天,我开始获得相同的断言`need !!((void *)0)'失败!错误,但前提是我必须使用当前的gcc/lib versios重新编译代码.

It looks that some thing has changed by some Ubuntu 13.10 sw updates. I had also code that has compiled and run without problem and just one day I started to get same Assertion `needed != ((void *)0)' failed! error but only if I compiled my code again with current gcc/lib versios.

调试后,我发现断言错误来自/lib/i386-linux-gnu/ld-2.17.so

After debugging I found out that the assert error comes from /lib/i386-linux-gnu/ld-2.17.so

      struct link_map *needed = find_needed (strtab + ent->vn_file, map);

  /* If NEEDED is NULL this means a dependency was not found
     and no stub entry was created.  This should never happen.  */
  assert (needed != NULL);

据说这是永远不会发生的,它没有说明需要什么但没有找到.一些gdb工作,我发现它需要libpthread.so.0.好的问题是,为什么/usr/bin/ld链接程序链接应用程序和ld.so对于此库的需求不同意.

It is said that this should never happen and it does not say what is needed but not found. Some gdb work and i found that it needs libpthread.so.0 . The good question is that why /usr/bin/ld linker linking application and ld.so disagree about need of this library.

我不是有意使用libpthread,但是从某个地方我到达了指向__pthread_key_create @@ GLIBC_2.0的链接映射参考,我不知道这是哪里来的,但可能会导致需要libpthread.so而不添加NEEDED libpthread.so.在objdump -p上为0,如下所示:

I did not intentionally use libpthread but from somewhere i got to my link map reference to __pthread_key_create@@GLIBC_2.0 I don't know where this comes but it may cause need of libpthread.so without adding NEEDED libpthread.so.0 as follows on objdump -p :

Dynamic Section:
 NEEDED               libglut.so.3
 NEEDED               libGLU.so.1
 NEEDED               libGL.so.1
 NEEDED               libstdc++.so.6
 NEEDED               libgcc_s.so.1
 NEEDED               libpthread.so.0
 NEEDED               libc.so.6

我没有找到此问题的根本原因,但至少没有解决方法.您需要将代码与-pthread选项链接,并对此库进行一些虚拟调用.

I did not find a root cause of this problem but least workaround. You need link your code with -pthread option and have some dummy call to this library .

在您的Makefile库中定义

Define in you Makefile libs

 -lglut -lGLU -lGL -lm  -pthread

然后包含一些虚拟函数,只需引用一些libpthread函数以使链接程序链接它,就可以得到所需的libpthread.so.0,然后ld.so就很方便了.

Then include some dummy function just refer some libpthread function to make linker link it and you get the NEEDED libpthread.so.0 and then ld.so is hap.

#include <pthread.h>
void junk() {
  int i;
  i=pthread_getconcurrency();
};

这对我有帮助,我希望对我有帮助.

This helped for me, i hope that it helps.

Ubuntu launcpad中有更多分析 https://bugs.launchpad .net/ubuntu/+ source/nvidia-graphics-drivers-319/+ bug/1248642?comments = all

There is more analysis in Ubuntu launcpadhttps://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642?comments=all

这篇关于运行已编译的C ++文件(使用OpenGL)时出错.错误:"ld.so检测到不一致:dl-version.c:224"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 00:42