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:
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 <pthread.h>
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
If you have an nvidia graphics card like mine, this might work for you
g++ -L/usr/lib/nvidia-304/ your-file.cc -lglut -lGLEW -lGL
Replace the 304 with the nvidia driver version. More details about this bug can be found at this link.