SFML and Qt Creator

Hello, I'm new to C++ and programming and I'm trying to make a graphic application with Qt Creator. I've downloaded a MinGW compiler that also comes with SFML (which I need for my application). However, when I put the line "#include <SFML/Graphics.hpp>" on the top of my program, I get a "'SFML/Graphics.hpp' file not found" message. My SFML files are located in C:\MinGW\SFML. How can I make Qt Creator recognize my SFML? Can anyone please explain me what exactly do I need to do? Any help is greatly appreciated.
Probably this: https://stackoverflow.com/questions/2752352/how-to-add-include-path-in-qt-creator
See either Jason B's response, or maybe Alex Maltsev's response, depending on your setup.
Last edited on
I think your .pro file should become something like this (I’ve highlighted the part you could be interested in):
TEMPLATE = app
CONFIG += console c++17
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp \
    Source1.cpp \
    Source2.cpp

HEADERS += \
    Header1.hpp \
    Header2.hpp

LIBS += -LC:/MinGW/SFML/lib/ -lsfml-audio-d -lsfml-graphics-d -lsfml-main-d -lsfml-network-d -lsfml-window-d -lsfml-system-d

INCLUDEPATH += C:/MinGW/SFML/include
DEPENDPATH += C:/MinGW/SFML/include


I think your .pro file should become something like this (I’ve highlighted the part you could be interested in):
TEMPLATE = app
CONFIG += console c++17
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp \
Source1.cpp \
Source2.cpp

HEADERS += \
Header1.hpp \
Header2.hpp

LIBS += -LC:/MinGW/SFML/lib/ -lsfml-audio-d -lsfml-graphics-d -lsfml-main-d -lsfml-network-d -lsfml-window-d -lsfml-system-d

INCLUDEPATH += C:/MinGW/SFML/include
DEPENDPATH += C:/MinGW/SFML/include


Thank you, but when adding these 3 rows the first error message was gone, however, when trying to run the program, I get these errors:

"cannot find -lsfml-audio-d"
"cannot find -lsfml-graphics-d"
"cannot find -lsfml-main-d"
"cannot find -lsfml-network-d"
"cannot find -lsfml-window-d"
"cannot find -lsfml-system-d"
"error: ld returned 1 exit status collect2.exe"
Last edited on
1) Do you have a directory “C:/MinGW/SFML/lib/” (or “C:\MinGw\SFML\lib” in Windows)?

2) Are there these files?
libsfml-audio-d.a
libsfml-graphics-d.a
libsfml-main-d.a
libsfml-network-d.a
libsfml-window-d.a
libsfml-system-d.a

(As a (Linux) convention, the initial “lib” part is removed from the file name and the extension is ignored. The initial “-l” is a GCC flag.)

3) The files that end in -d are the debug version of the libraries. Maybe you have got only the release versions.
Try this line:

LIBS += -LC:/MinGW/SFML/lib/ -lsfml-audio -lsfml-graphics -lsfml-main -lsfml-network -lsfml-window -lsfml-system
Last edited on
Yes, my directory is "C:\MinGw\SFML\lib". I have the same files, but like you said, without "-d" at the end of their names. But after trying with the new line I'm still getting the same error messages plus this one "skipping incompatible C:/MinGW/SFML/lib/libsfml-audio.a when searching for -lsfml-audio" and also for the rest of the libraries.
Last edited on
"skipping incompatible" --> If memory serves me, this has to do with 32-bit vs. 64-bit incompatibilities. Either the library is 32-bit and your compiling 64-bit, or vice-versa.

Did you build the .a files yourself or did you download them?
NOTE: read this only after having checked what Ganado told you in his last post (the ‘jist’ of this post is more or less the same).

- - -
"skipping incompatible C:/MinGW/SFML/lib/libsfml-audio.a when searching for -lsfml-audio" and also for the rest of the libraries.

I’m running out of options :-(

1) When you installed Qt, did you tick the option for taking the compiler along or not?
2) What compiler are you using then with Qt Creator, GCC or the Microsoft one?
2) What version of the Qt libraries have you installed, the version compiled for GCC or the version compiled for Visual C++?

(Please note: as far as I know, there’s no precompiled 64bit version of the Qt libraries for GCC)


- - -
Searching for your error I got here:
https://en.sfml-dev.org/forums/index.php?topic=21300.0
It’s 3 years old, but it seems related.
It suggests to use the -v option to check what the compiler is linking against.
In the .pro file you can add:
QMAKE_CXXFLAGS += -v
(beware! The -v option might increase the compiler verbosity a lot!!)


- - -
Here, instead, it suggest to use the “-s” version of the SFML libraries.
https://www.sfml-dev.org/tutorials/2.5/start-cb.php
You could try:

LIBS += -LC:/MinGW/SFML/lib/ -lsfml-audio-s-d -lsfml-graphics-s-d -lsfml-main-s-d -lsfml-network-s-d -lsfml-window-s-d -lsfml-system-s-d

or

LIBS += -LC:/MinGW/SFML/lib/ -lsfml-audio-s -lsfml-graphics-s -lsfml-main-s -lsfml-network-s -lsfml-window-s -lsfml-system-s


- - -
What about ‘installing’ the SFML library in a more ‘traditional’ way?
Just download the proper (check the compiler you have told Qt Creator to use!) compressed archive from here:
https://www.sfml-dev.org/download/sfml/2.5.1/
and unzip it into a not too nested directory you have read-write privileges on.

Then modify the path in the .pro file accordingly:
LIBS += -LC:/MinGW/SFML/lib/ <-- keep the “-L” flag, modify from ‘C’ on
INCLUDEPATH += C:/MinGW/SFML/include
DEPENDPATH += C:/MinGW/SFML/include
Last edited on
Ok, so after downloading a SFML version from the official website and replacing the files in my "/lib" folder with the ones that came with the archive and by using these lines:


LIBS += -LC:/MinGW/SFML/lib/ -lsfml-audio-d -lsfml-graphics-d -lsfml-main-d -lsfml-network-d -lsfml-window-d -lsfml-system-d

INCLUDEPATH += C:/MinGW/SFML/include
DEPENDPATH += C:/MinGW/SFML/include


I am no longer getting any errors when trying to run my program. However, all I get is a blank console with a blinking cursor instead of my graphic. I am actually using a ready-made program that comes with the book that I'm reading so I'm trying to make it work on my computer. However, in my book the executing of the program is performed by another environment and not by Qt Creator, which is somehow confusing to me. So I went to the "debug" folder of the program in "Documents", where is also the created .exe file. But after clicking on it, I'm getting "The application was unable to start correctly 0xc00007b" error message. What could be the reason for this? The program that's also available for download with the book consists of 3 files - the main.cpp and the class files (1 .cpp and one .h file). When creating the program I've chosen a Non-Qt Project -> Plain C++ Application. The program normally opens a window with a purple circle in it. Is this the right option in my case? Or maybe there's something else that I'm missing?
I'm new to C++ and programming and I'm trying to make a graphic application with Qt Creator.

A lot of the following has been said but, in saying the above you have probably picked on the best and worst piece of kit to start out learning C++ and developing games using SFML without using their IDE. Combining that with minGW and you really have your work cut out.

1. Why even use QtCreator because I assume SFML are true to their word and you can use C++ on their platform/bindings?

However ...
2. If you have QtCreator setup and running just make sure with an example Qt provide that QtCreator is working properly. If it is then keep going, if not use the Qt maintenance tool, remove QtCreator and replace it.

3. If you have your heart set on minGW then you have to include it as part of the compiler kit which is accessed through the QtCreator preferences pulldown menu. (If QtCreator is running properly then you don't need minGW anyway, keeping in mind with a Mac you may need to install Xcode command line tools, a simple install)

4. Once you're in the working QtCreator environment with a new project all you do wrt the file you're trying to #include is:
In the file menu just add the required file. It will then appear in the file display. It's now part of the project and will appear automatically in the .pro file.
Once the file is there you simply add your #include ... line(s) to the relevant files in your program.

5. I suspect getting the included file alone is not the end of the story though. You can Google "SFML and Qt" The SFML website has a tutorial on what you do and there are YouTube tutorials.

Above all,
Good luck!


So after downloading the environment recommended in the book, I got the program working. It may not be the best solution, but at least now I'll be able to learn further and go on with making other graphic applications. Thanks everyone here for the help!
Topic archived. No new replies allowed.