Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Qt and glewInit() on Linux leads to segfault

Qt and glewInit() on Linux leads to segfault

Scheduled Pinned Locked Moved Solved Installation and Deployment
2 Posts 1 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ProgSysP Offline
    ProgSysP Offline
    ProgSys
    wrote on last edited by
    #1

    I am using a QOpenGLWidget with glew to render a scene.
    On Windows everything works fine, but on Linux as soon as glewInit() is called, which is placed inside initializeGL(), the app crashes with a segfault.
    I searched online and can't find anything about it. Am I missing something, do I also need to link something else? I am thankful for any help.

    #include <GL/glew.h>
    #include <QDebug>
    
    void MyOpenGLWidget::initializeGL(){
    	qDebug()<<"====== Info ======";
    	qDebug()<<"OpenGL version: "<<reinterpret_cast<const char*>(glGetString(GL_VERSION)); // 4.5.0 NVIDIA 352.63
    	qDebug()<<"GLSL version: "<<reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION)); // 4.50 NVIDIA
    	qDebug()<<"Vendor: "<<reinterpret_cast<const char*>(glGetString(GL_VENDOR)); // NVIDIA Corporation
    	qDebug()<<"Renderer: "<<reinterpret_cast<const char*>(glGetString(GL_RENDERER)); // GeForce GTX 860M/PCIe/SSE2
    	qDebug()<<"Extensions: "<<reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); // big list
    	qDebug()<<"====== End ======";
    
    	GLenum err = glewInit(); // segfault here
    	if(err != GLEW_OK){
    		QMessageBox::critical(this, "Error", QString("Failed to initialize GLEW! Msg: ")+reinterpret_cast<const char*>(glewGetErrorString(err) ));
    		exit (EXIT_FAILURE);
    	}
    }
    

    I build my project using CMake:

    # A cmake tempalte for a c++ project using QT and glew(OpenGl).
    string(REPLACE "/" ";" p2list "${CMAKE_SOURCE_DIR}")
    string(REPLACE "\\" ";" p2list "${p2list}")
    list(REVERSE p2list)
    list(GET p2list 0 first)
    list(GET p2list 1 ProjectId)
    string(REPLACE " " "_" ProjectId ${ProjectId})
    project(${ProjectId})
    
    include(${CMAKE_MODULE_PATH}/doxygen.cmake)
    include(${CMAKE_MODULE_PATH}/macros.cmake)
    
    set(CMAKE_CONFIGURATION_TYPES Debug;Release)
    set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x") # Use c++11
    
    # == All the needed QT packages (install QT in windows or linux) ==
    set(QTCP_PROJECT_DIR ${PROJECT_SOURCE_DIR})
    
    set(CMAKE_AUTOMOC ON)
    #set(CMAKE_AUTOUIC ON)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    # find QT5 cmake files on windows
    IF (WIN32)
    find_path(QT_CMAKE_DIR Qt5/Qt5Config.cmake
      PATH_SUFFIXES cmake
      PATHS "D:/Qt/5.5/mingw492_32/lib" "C:/Qt/5.5/mingw492_32/lib" "E:/Qt/5.5/mingw492_32/lib" 
      DOC "The path to the QT cmake files."
    )
    set (CMAKE_PREFIX_PATH ${QT_CMAKE_DIR}) 
    endif(WIN32)
    
    #find_package(Qt5Core REQUIRED )
    find_package(Qt5Widgets REQUIRED)
    find_package(Qt5OpenGL REQUIRED)
    
    find_package(Qt5Quick REQUIRED)
    find_package(Qt5QuickWidgets REQUIRED)
    
    include_directories(
    	${Qt5Widgets_INCLUDES}
    	${QT_QTOPENGL_INCLUDE_DIR} 
    )
    
    add_definitions(${Qt5Widgets_DEFINITIONS})
    
    #set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} )
    
    # Open Gl lib
    link_dependency(OpenGL3)
    
    # The OpenGL Extension Wrangler Library (https://github.com/Perlmint/glew-cmake.git)
    add_subdirectory("${EXTERNALS_PATH}/glew-cmake")
    link_dependency(GLEW) 
    
    set(ALL_LIBRARIES ${ALL_LIBRARIES} Qt5::Widgets Qt5::OpenGL Qt5::Qml Qt5::Quick Qt5::QuickWidgets)  
    
    #GLM math libaray (https://github.com/g-truc/glm)
    file(GLOB_RECURSE GLM
        "${EXTERNALS_PATH}/GLM/glm/*.hpp")
    include_directories("${EXTERNALS_PATH}/GLM")
    
    add_definitions(
            -DGLM_FORCE_RADIANS
            -DGLM_FORCE_PURE
            -DNOMINMAX
    		-DGLM_ENABLE_EXPERIMENTAL
    )
    
    # Collect all code
    set(EXTERNAL_CODE
            ${GLM}
            ${GLEW}
            ${MOCSrcs}
            ${UI_SRCS}
    )
    
    # Include externals folder
    include_directories(${EXTERNALS_PATH})
    
    include_directories(
        ${CORE_PATH}
    )
    
    add_definitions(-DSHADERS_PATH="${SHADERS_PATH}")
    add_definitions(-DRESOURCES_PATH="${RESOURCES_PATH}")
    
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
      # using Clang
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
      add_definitions(-Wall -Wextra)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
      # using Intel C++
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
      add_definitions(/W2)
    endif()
    
    set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
    GENERATE_SUBDIRS(ALL_LIBRARIES ${LIBRARIES_PATH} ${PROJECT_BINARY_DIR}/libraries)
    
    set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
    GENERATE_SUBDIRS(ALL_EXECUTABLES ${EXECUTABLES_PATH} ${PROJECT_BINARY_DIR}/executables)
    

    The subproject itself:

    cmake_minimum_required(VERSION 2.8.11)
    #if(CMAKE_VERSION VERSION_GREATER "2.8.11")
        #CMAKE_POLICY(SET CMP0022 OLD)
    #endif()
    
    get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
    string(REPLACE " " "_" ProjectId ${ProjectId})
    project(${ProjectId})
    
    
    message( "LIBRARIES_PATH: " ${LIBRARIES_PATH} )
    
    include_directories(
        ${LIBRARIES_PATH}
    )
    
    file(GLOB_RECURSE SOURCES *.cpp)
    file(GLOB_RECURSE HEADER *.h)
    
    
    # find and build the given UI files
    set(UI_SRCS "") #all srcs files
    file(GLOB children_files RELATIVE ${UI_PATH} ${UI_PATH}/*)
    FOREACH(ui_file ${UI_FILES})
    	if(NOT IS_DIRECTORY ${UI_PATH}/${ui_file})
    		if(${ui_file} MATCHES "..*[.]ui")
    			string(REPLACE ".ui" "" ui_file_name ${ui_file})
    			QT5_WRAP_UI("UI_${ui_file_name}_Src" ${UI_PATH}/${ui_file})
    			set(UI_SRCS ${UI_SRCS} "${UI_${ui_file_name}_Src}") 
    		endif()
    	endif()
    ENDFOREACH()
    
    add_executable(${ProjectId} ${SOURCES} ${HEADER} ${EXTERNAL_CODE} ${UI_SRCS})
    
    message( "EXTERNAL_CODE: " ${EXTERNAL_CODE} )
    message( "ALL_LIBRARIES: " ${ALL_LIBRARIES} )
    
    target_link_libraries(
        ${ProjectId}
        ${ALL_LIBRARIES}
        ${GTK3_LIBRARIES}
    )
    
    1 Reply Last reply
    0
    • ProgSysP Offline
      ProgSysP Offline
      ProgSys
      wrote on last edited by
      #2

      Looks like the new version of glew is just not working, I checkout an older version and everything is now working.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved