Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: MinGW + SFML + CLion (Windows 10)  (Read 9374 times)

0 Members and 1 Guest are viewing this topic.

sweet_weakness

  • Newbie
  • *
  • Posts: 5
    • View Profile
MinGW + SFML + CLion (Windows 10)
« on: April 03, 2020, 01:47:15 pm »
Hello, I tried everything to set it up, but it didn't help. I use MinGW 32-bit (I ve downloaded it from link on sfml download page) and SFML for MinGW 32-bit. Here are my CMake and code (default).



#include <SFML/Graphics.hpp>


int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);


    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }


        window.clear();
        window.draw(shape);
        window.display();
    }


    return 0;
}
 



cmake_minimum_required(VERSION 3.14)
set(PROJECT_NAME MyGame)


project(${PROJECT_NAME})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -static")


set(CMAKE_CXX_STANDARD 17)


set(SOURCE_FILES main.cpp)


if (CMAKE_BUILD_TYPE STREQUAL "Release")
    add_executable(${PROJECT_NAME} WIN32 ${SOURCE_FILES})
else ()
    add_executable(${PROJECT_NAME} ${SOURCE_FILES})
endif ()


set(SFML_ROOT "${CMAKE_SOURCE_DIR}/SFML-2.5.1")
set(SFML_DIR "${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/cmake/SFML")
#set(SFML_STATIC_LIBRARIES TRUE)


set(CMAKE_MODULE_PATH "${SFML_ROOT}/lib/cmake/SFML")
find_package(SFML 2 REQUIRED COMPONENTS audio graphics window system)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    link_directories(${SFML_LINK_DIR})
    target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
else ()
    message("SFML NOT FOUND")
endif()
 


I've tried everything; I need SFML libs folder in my project folder.

====================[ Build | MyGame | Release ]================================
"C:\Program Files\JetBrains\CLion\bin\cmake\win\bin\cmake.exe" --build "D:\JetBrains Projects\CLion Projects\MyGame\cmake-build-release" --target MyGame -- -j 4
-- Found SFML 2.5.1 in D:/JetBrains Projects/CLion Projects/MyGame/SFML-2.5.1/lib/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: D:/JetBrains Projects/CLion Projects/MyGame/cmake-build-release
[ 50%] Building CXX object CMakeFiles/MyGame.dir/main.cpp.obj
D:\JetBrains Projects\CLion Projects\MyGame\main.cpp:1:10: fatal error: SFML/Graphics.hpp: No such file or directory
 #include <SFML/Graphics.hpp>
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
mingw32-make.exe[3]: *** [CMakeFiles\MyGame.dir\build.make:62: CMakeFiles/MyGame.dir/main.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:72: CMakeFiles/MyGame.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:84: CMakeFiles/MyGame.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: MyGame] Error 2
 
« Last Edit: April 03, 2020, 02:15:36 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: MinGW + SFML + CLion (Windows 10)
« Reply #1 on: April 03, 2020, 02:17:41 pm »
See the following thread on how to write CMake for SFML from SFML 2.5.1 onwards: https://en.sfml-dev.org/forums/index.php?topic=24070.0
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sweet_weakness

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: MinGW + SFML + CLion (Windows 10)
« Reply #2 on: April 03, 2020, 04:27:15 pm »
See the following thread on how to write CMake for SFML from SFML 2.5.1 onwards: https://en.sfml-dev.org/forums/index.php?topic=24070.0

I tried everything even it. It works only if i merge sfml and mingw folders.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: MinGW + SFML + CLion (Windows 10)
« Reply #3 on: April 03, 2020, 05:04:06 pm »
What if you move the add_executable() below the searching for SFML?
I don't know when exactly CMake resolves the include directories, but maybe if they're missing when you add an executable, then they won't be seen by your source code?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sweet_weakness

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: MinGW + SFML + CLion (Windows 10)
« Reply #4 on: April 04, 2020, 11:41:50 am »
That didn't help. Btw, yesterday i got 0x0000...00135 exit code (using this CMake).

Code: [Select]
cmake_minimum_required(VERSION 3.1)

project(MyGame)

## If you want to link SFML statically
# set(SFML_STATIC_LIBRARIES TRUE)

## In most cases better set in the CMake cache
set(SFML_DIR "${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/cmake/SFML")

find_package(SFML 2.5.1 COMPONENTS graphics REQUIRED)
add_executable(MyGame main.cpp)
target_link_libraries(MyGame sfml-graphics)

When i set static libs on true, I get same error (can't find SFML/Graphics.hpp etc)

sweet_weakness

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: MinGW + SFML + CLion (Windows 10)
« Reply #5 on: April 07, 2020, 09:31:57 pm »
What if you move the add_executable() below the searching for SFML?
I don't know when exactly CMake resolves the include directories, but maybe if they're missing when you add an executable, then they won't be seen by your source code?

Any ideas?)

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MinGW + SFML + CLion (Windows 10)
« Reply #6 on: April 09, 2020, 11:38:40 am »
Hey there,
i use a similar setup as you (but mingw-w64 instead of mingw). I had also some trouble getting newest SFML version to run with CMAKE and CLION. However with Laurents help i was able to get it to run. Here the whole process is described in detail, it may be helpful for you.

https://en.sfml-dev.org/forums/index.php?topic=26960.0

sweet_weakness

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: MinGW + SFML + CLion (Windows 10)
« Reply #7 on: April 09, 2020, 05:25:30 pm »
Hey there,
i use a similar setup as you (but mingw-w64 instead of mingw). I had also some trouble getting newest SFML version to run with CMAKE and CLION. However with Laurents help i was able to get it to run. Here the whole process is described in detail, it may be helpful for you.

https://en.sfml-dev.org/forums/index.php?topic=26960.0

Thanks. Is it normal that I need to add .dll's myself (I mean to copy .dll's in my cmake-build folder)? I thought that it has to do it itself after compiling project.

 

anything