MinGW + SFML giving error code

2019-08-02 08:43发布

问题:

I'm using SFML and MinGW to make a game. I'm using MinGW because I'm using CLion as my IDE since I'm used to the JetBrains suite. Anyways, I've installed MinGW 4.9.2 and got the respective SFML and added the SFML_ROOT to my environment variables. Now, whenever I run it it gives me this: Process finished with exit code -1073741515 (0xC0000135), the application doesn't boot obviously.

My CMakeLists is as follows:

cmake_minimum_required(VERSION 3.2)
project(airport-simulator)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES
    main.cpp)

add_executable(${PROJECT_NAME} ${SOURCE_FILES} main.cpp)

# SFML
set(SFML_ROOT "${CMAKE_SOURCE_DIR}/sfml")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES})
endif()

My main.cpp is:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Airport Simulator");
    sf::CircleShape shape(80);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) window.close();
        }

        window.clear(sf::Color::Black);
        window.draw(shape);
        window.display();
    }

    return 0;
}

My file structure:

Project
|-- .idea
|-- cmake
|   `-- FindSFML.txt
|-- sfml
|-- .gitignore
|-- CMakeLists.txt
`-- main.cpp

I've tried replacing the SFML library and updating/changing the MinGW version all with no success. Any ideas?

Cheers

回答1:

I've run into a similar issue myself and only after starting the application outside of the CLion IDE you'll actually get the informative error, which is that you're missing a DLL.

If you use the dynamic libraries, you'll have to copy the DLLs into the working directory or next to your application. Also don't forget to copy over the OpenAL DLL that ships with SFML if you ever want to use the audio module.

I really hope JetBrains can report the missing DLL error better in their IDE.



标签: c++ mingw clion