[QUOTE=Dark Photon;1286799]Here on my Linux box, glewInit() can be the very first call in main().
Let’s see some code.
Also bring this up in your favorite debugger and see if you can get more useful data (as far as a stack trace or more details on why you’re getting a segfault). E.g. bring up in gdb, run, then do a “where”.
Finally, let’s see how you’ve got it linked. Do an “ldd <exec>”.[/QUOTE]
Here is a testing code which works on my Mac OSX, but not on this Ubuntu 16.04.
// Include standard headers
#include <stdio.h>
#include <stdlib.h>
// Include GLEW. Always include it before gl.h and glfw.h, since it's a bit magic.
#include <GL/glew.h>
// Include GLFW
#include <GLFW/glfw3.h>
// Include GLM
#include <glm/glm.hpp>
using namespace glm;
int main(){
// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW
" );
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL
// Open a window and create its OpenGL context
GLFWwindow* window; // (In the accompanying source code, this variable is global)
window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.
" );
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window); // Initialize GLEW
glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW
");
return -1;
}
// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
do{
// Draw nothing, see you in tutorial 2 !
// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
}
The code compiles well in Ubuntu 16.04, but it gives an segmentation fault error while running. Here is the error message
[NOTE]Segmentation fault (core dumped)[/NOTE]
I’m not very familiar with debugging tools, usually I just output to debug. But running gdb a.out followed by where does give some output saying
(gdb) r
Starting program: /home/paul/Research/Samples/GL_examples/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library “/lib/x86_64-linux-gnu/libthread_db.so.1”.
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) where
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff7ba19c7 in glxewInit () from /usr/lib64/libGLEW.so.2.0
#2 0x00007ffff7ba9cbd in glewInit () from /usr/lib64/libGLEW.so.2.0
#3 0x0000000000403c2e in main ()
(gdb)
Here is an output of ldd a.out
linux-vdso.so.1 => (0x00007ffe560d5000)
libGLEW.so.2.0 => /usr/lib64/libGLEW.so.2.0 (0x00007f6da0fd9000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6da0cb0000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6da0a92000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6da088e000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f6da0686000)
libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f6da047a000)
libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f6da0277000)
libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f6da0071000)
libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f6d9fe66000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f6d9fb2c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6d9f763000)
libGL.so.1 => /usr/lib/nvidia-381/libGL.so.1 (0x00007f6d9f4d2000)
/lib64/ld-linux-x86-64.so.2 (0x0000561bea047000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f6d9f2c0000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f6d9f0b6000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f6d9eeaf000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f6d9ec8d000)
libGLX.so.0 => /usr/lib/nvidia-381/libGLX.so.0 (0x00007f6d9ea5c000)
libGLdispatch.so.0 => /usr/lib/nvidia-381/libGLdispatch.so.0 (0x00007f6d9e773000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f6d9e56f000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f6d9e368000)