(Im using Clion and Cmake on Macosx Intel chip)
I wan't to make a Window Application with GLEW. But i get this error:
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
I heard that you should define "GLEW_STATIC" in the preprocessing. But I have no idea how Clion works
My main.cpp:
#include "GL/glew.h"
#include <GLFW/glfw3.h>
int main()
{
GLFWwindow* window;
if (!glfwInit())
return -1;
glewInit();
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
and my cmake:
cmake_minimum_required(VERSION 3.22)
project(renderer)
set(CMAKE_CXX_STANDARD 14)
include_directories(/usr/local/Cellar/glfw/3.3.8/include)
include_directories(/usr/local/Cellar/glew/2.2.0_1/include)
add_definitions(-DGLEW_STATIC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework CoreFoundation -framework OpenGL -framework GLUT ")
add_executable(renderer main.cpp)
target_link_libraries(renderer /usr/local/Cellar/glfw/3.3.8/lib/libglfw.3.3.dylib)
target_link_libraries(renderer /usr/local/Cellar/glew/2.2.0_1/lib/libGLEW.2.2.dylib)
How do i fix this problem?
CodePudding user response:
glewInit()
requires a current OpenGL context to operate correctly. As written in your code glewInit()
will fail and leave its glClear()
function-pointer set to nullptr
.
Call glewInit()
after glfwMakeContextCurrent()
'returns' GLFW_NO_ERROR
and verify that it returns GLEW_OK
.