Home > database >  glfwInit() causes segmentation fault with exit code -1073741515 (0xc0000135)
glfwInit() causes segmentation fault with exit code -1073741515 (0xc0000135)

Time:11-17

I have been trying to get one my older projects to work which uses some OpenGL code. I am unable to produce a working executable. All that happens is, just by calling glfwInit(), is a segmentation fault:

enter image description here

My best guess is that it somehow doesnt use/find the glfw dll i am trying to use.


Let me explain my current setup:

  1. I have installed glfw using msys2:

    pacman -S mingw-w64-x86_64-glfw
    
  2. I have created a glad header and source file

  3. I wrote a simple cmake-file (which also used to work 2 years ago)

    cmake_minimum_required(VERSION 3.23)
    project(2DGameEngine)
    
    find_package(glfw3 3.3 REQUIRED)
    find_package(OpenGL REQUIRED)
    
    set(CMAKE_CXX_STANDARD 23)
    
    file(GLOB_RECURSE SRCS src/*.cpp src/*.c)
    
    add_executable(2DGameEngine ${SRCS})
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow")
    
    target_link_libraries(2DGameEngine glfw)
    target_link_libraries(2DGameEngine OpenGL::GL)
    
  4. I used the simplest example I could find:

    #include "glad.h"
    #include <GLFW/glfw3.h>
    #include <iostream>
    
    int main()
    {
        // glfw: initialize and configure
        // ------------------------------
        if(!glfwInit()){
            std::cout << "error" << std::endl;
            exit(1);
        }
        return 0;
    }   
    

Yet I am unable to get rid of the segmentation fault when calling glfwInit(). I assume it has to do with some .dll missing but I have no idea how I could check this. I am very happy for any help.

CodePudding user response:

0xc0000135 is the error you get when your Windows OS could not find a required dll when executing your program. There is a handy site that decodes these types of errors here: https://james.darpinian.com/decoder/?q=0xc0000135

Use this program: https://github.com/lucasg/Dependencies to figure out what dll can not be found and then put that dll in the same folder as the executable or edit your OS PATH environment variable to contain the folder which has that dll.

Here is a good article on how to set the OS PATH environment variable: https://www.computerhope.com/issues/ch000549.htm

There are several other options contained in this Microsoft document which explains how and where your OS searches for dlls: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications

  • Related