I am writing an OpenGL application on Linux and I can easily create a window using GLUT , but as soon as I even get in -lGL with -lGL , I get segfault. Any ideas that might be causing this?
I do not get any warnings or compiler errors even with -Wall . Only when I run the program does it give me segfault.
I have not used gdb before, but does this information help?
(gdb) run Starting program: /home/drjrm3/code/dc/c++/dc.exe Program received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? () (gdb) backtrace
I brought this to a minimal example, now I'm still confused about what is going on:
#include <cstdio> #include <string> #include <cstdlib> #include <iostream> #include <vector> #include <GL/freeglut.h> #include <GL/gl.h> using namespace std; /********************\ * Global variables * \********************/ string fname; // gl vars int WinWidth = 800; int WinHeight = 800; int WinPos1 = 400; int WinPos2 = 400; void gl2Dinit(int argc, char** argv); void myInit(); void draw(); void mouseFunc(int button, int state, int x, int y); void keyboardFunc(unsigned char key, int x, int y); /****************\ * Main routine * \****************/ int main(int argc, char** argv) { fprintf(stderr, "We got this far ...\n"); return 0; } void gl2Dinit(int argc, char** argv) { // glutInit(&argc, argv); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ); /// define window prorperties glutInitWindowSize(WinWidth, WinHeight); glutInitWindowPosition(WinPos1, WinPos2); glutCreateWindow("Title!"); /// intitialize myInit(); /// callback functions glutDisplayFunc(draw); glutMouseFunc(mouseFunc); glutKeyboardFunc(keyboardFunc); // glut main loop glutMainLoop(); } void myInit() { } void draw() { } void mouseFunc(int button, int state, int x, int y) { } void keyboardFunc(unsigned char key, int x, int y) { }
I compile with g++ -g -o dc.exe xdriver.cpp -I/usr/include/GL -lglut -lGL -DLINUX -Wall , and when I run the code, it doesn't print anything ... I just get a Segmentation fault (core dumped) . What bothers me is that he should do nothing but print, and then leave ... but for some reason it disappears.
As soon as I remove -lGL , I run the program and it prints “We got this far ...” and then exit.