Last active
April 21, 2018 04:03
-
-
Save luismrsilva/efe2eb2909d0352690bb5bd384730757 to your computer and use it in GitHub Desktop.
Fix for segmentation fault before main when using OpenGL functions AND std under Linux Ubuntu.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Fix for segmentation fault before main | |
when Using OpenGL functions AND std | |
under Linux Ubuntu. | |
2016-10-25 luismrsilva | |
The problem is similar to this (solution is based on it too): | |
http://stackoverflow.com/questions/31579243/segmentation-fault-before-main-when-using-glut-and-stdstring | |
To see details use: | |
$ export LD_DEBUG=all | |
before running. | |
Fix: | |
Link with -pthread | |
If it does not work, also put the following code somewhere to make g++ assume pthread is used. | |
*/ | |
// We check for __unix__ because this was only tested on Linux. | |
#if defined(__unix__) | |
#include <pthread.h> | |
void* simpleFunc(void*) { | |
return NULL; | |
} | |
void forcePThreadLink() { | |
pthread_t t1; | |
pthread_create(&t1, NULL, &simpleFunc, NULL); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! I run into the same problem, so thanks for the snippet!
I used
pthread_getconcurrency
instead to make it a little simpler, as in:As far as I can tell, this is only needed with g++:
-pthead
is enough for clang++.