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 =>  (0x00007ffe14f5e000) => /usr/lib/x86_64-linux-gnu/ (0x00007f9b24659000) => /usr/lib/nvidia-352/ (0x00007f9b24329000) => /usr/lib/x86_64-linux-gnu/ (0x00007f9b24025000) => /lib/x86_64-linux-gnu/ (0x00007f9b23e0f000) => /lib/x86_64-linux-gnu/ (0x00007f9b23a4a000) => /usr/lib/x86_64-linux-gnu/ (0x00007f9b23715000) => /lib/x86_64-linux-gnu/ (0x00007f9b2340f000) => /usr/lib/x86_64-linux-gnu/ (0x00007f9b231ff000) => /usr/lib/x86_64-linux-gnu/ (0x00007f9b22ff9000) => /usr/lib/nvidia-352/tls/ (0x00007f9b22df6000) => /usr/lib/nvidia-352/ (0x00007f9b20363000) => /usr/lib/x86_64-linux-gnu/ (0x00007f9b20151000) => /lib/x86_64-linux-gnu/ (0x00007f9b1ff4d000)
 /lib64/ (0x00007f9b248a3000) => /usr/lib/x86_64-linux-gnu/ (0x00007f9b1fd2e000) => /usr/lib/x86_64-linux-gnu/ (0x00007f9b1fb2a000) => /usr/lib/x86_64-linux-gnu/ (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?