error running a compiled C++ file (uses OpenGL). Error: “Inconsistency detected by ld.so: dl-version.c: 224”

后端 未结 2 1015
广开言路
广开言路 2021-02-19 19:27

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:



        
2条回答
  •  生来不讨喜
    2021-02-19 19:46

    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.

    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);
    

    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.

    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
    

    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 .

    Define in you Makefile libs

     -lglut -lGLU -lGL -lm  -pthread
    

    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 
    void junk() {
      int i;
      i=pthread_getconcurrency();
    };
    

    This helped for me, i hope that it helps.

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

提交回复
热议问题