Thursday, March 24, 2016

Why default GL library crash with string declaration on Linux?

How can this simple OpenGL program can throw a segmentation fault?
#include "GL/glew.h"
#include "GL/freeglut.h"
#include <iostream>


std::string a;

int main(int argc, char **argv)
{
   return 0;
}

I don't think this is a joke. Even if I omit the string, the program will still running fine with cout. Am I wrongly setup the IDE? Things were settled until I found this bug report, this could be a serious problem. I run the ldd check and find it there isn't any linkage to pthread.

kokhoe@KOKHOE:~/workspacec/OpenGL1/Debug$ ldd OpenGL1
 linux-vdso.so.1 =>  (0x00007ffe14f5e000)
 libglut.so.3 => /usr/lib/x86_64-linux-gnu/libglut.so.3 (0x00007f9b24659000)
 libGL.so.1 => /usr/lib/nvidia-352/libGL.so.1 (0x00007f9b24329000)
 libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9b24025000)
 libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9b23e0f000)
 libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9b23a4a000)
 libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f9b23715000)
 libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9b2340f000)
 libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007f9b231ff000)
 libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f9b22ff9000)
 libnvidia-tls.so.352.63 => /usr/lib/nvidia-352/tls/libnvidia-tls.so.352.63 (0x00007f9b22df6000)
 libnvidia-glcore.so.352.63 => /usr/lib/nvidia-352/libnvidia-glcore.so.352.63 (0x00007f9b20363000)
 libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f9b20151000)
 libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9b1ff4d000)
 /lib64/ld-linux-x86-64.so.2 (0x00007f9b248a3000)
 libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f9b1fd2e000)
 libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f9b1fb2a000)
 libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f9b1f924000)

But interestingly, I see there is a link with nVidia driver. I then find out there is another libGL did installed in /usr/lib/nvidia-352. If I link my program with this GL library, everything would go fine.

Hmmm... Could it be the permanent workaround for this problem?