0

I am trying to learn to make 2d games using c++ with the SFML library. I am using windows, but I would prefer to use the Atom text editor instead of Visual Studio. I did a lot of research on how to do this, but I still do not know how to use the SFML library with Atom. So, how would I go about implementing the SFML library in my c++ project written in Atom. Thank you!

  • Am I correct in assuming that you are able to write and compile non-SFML applications using Atom, but when you try to compile SFML applications you get some error like "fatal error: SFML/Graphics.hpp: No such file or directory" ? If so, I think I have an answer for you that doesn't involve waiting for an Atom package. – A. Howells Jun 19 '19 at 00:05
  • And by the way, the text of the SFML site says that they support [tag:mingw], but then they link to [tag:mingw-w64] e.g. on [this page](https://www.sfml-dev.org/download/sfml/2.5.1/). They say in red that your compiler version needs to match theirs, so in theory using MinGW instead of MinGW-w64 could cause issues. (That said, I haven't encountered any issues using MinGW with SFML and Atom, so...) – A. Howells Jun 19 '19 at 00:37
  • How would I go about implementing SFML with MinGW on Atom? –  Jun 19 '19 at 02:49

2 Answers2

2

This answer supposes that you've downloaded the 32-bit MinGW version of SFML, and you'd like to compile programs written in Atom from the command line1. Inside of the SFML folder you just downloaded, there are three folders which are important for us right now: bin, lib, and include.

  • The bin folder contains DLLs. In this answer I'm only going to talk about dynamic linking to SFML, since that's what I have experience with. To run any dynamically linked executable built using SFML, you'll need to copy all of the relevant DLLs into the same folder as the executable. (Which are the relevant ones? The easy solution is to just copy all of them.2)

  • The lib folder contains libraries (files with the .a extension). If you go to the folder where you installed MinGW (the default is C:\MinGW), and then follow the path \lib\gcc\mingw32\8.2.0, you should be in a folder with a few subfolders, some .o files, and a bunch of .a files. Copy into here all of the files from the SFML lib folder. Now MinGW knows about the SFML libraries.

  • Lastly, the include folder contains a folder named SFML, which contains all of the SFML header files. Copy the SFML folder. Now remember the folder that we dumped all of the .a files into in the last step? That folder should have a subfolder named include, which contains a folder named C++, which contains all of the standard C++ headers (iostream, algorithm, etc.). Into that C++ folder paste the SFML folder that we picked up just a second ago. (Not the contents of the folder, but rather the folder itself.) Now MinGW knows about the SFML headers, so we can safely type e.g. #include <SFML/Graphics.hpp>

To compile, for example, the file main.cpp at the end of this tutorial and dynamically link it with Atom, you would run the command g++ main.cpp -lsfml-graphics -lsfml-window -lsfml-system inside of cmd.exe.


Disclaimer: Copying the libraries and include folder is not the method recommended by SFML. Instead, they suggest using command line arguments to tell g++ where to look. But IMO (1) their method is more of a pain for first-time users, and (2) first-time users are unlikely to be using multiple compilers or multiple versions of SFML. (If you are using multiple compilers or multiple versions of SFML, you'll want to do it their way. In that case let me know and I can try to help.)


1) It's possible you're actually looking to compile directly in Atom at the click of a button (F5 by default?). If you already know how to compile non-SFML applications directly in Atom, then I think the above should be enough for you to compile SFML applications too, as long as you set your default compiler flags appropriately in Atom. (By which I mean: For the example above your flags should include -lsfml-graphics, -lsfml-window, and -lsfml-system, in that order).

2) To figure out what DLLs you need, you can add them all and start removing them until your application doesn't work. Alternatively, keep these three things in mind:

  • You always need openal32.dll
  • You need the DLLs that you linked to when compiling
  • You need the versions with "-d" (e.g. sfml-graphics-d-2.dll) if you're compiling in debug mode, and you need the versions without it otherwise

So in the case of the example above, you only need openal32.dll, sfml-graphics-2.dll, sfml-window-2.dll, and sfml-system-2.dll.

A. Howells
  • 136
  • 4
  • Thanks, this worked. Is there any way to move the DLLs into a separate folder? –  Jun 19 '19 at 16:11
  • @SuspiciousGoat I've never bothered to do that, so I can't give you an answer with confidence. Maybe try the suggestion [here](https://stackoverflow.com/a/5140472/9378490)? Also, you don't actually need most of the DLLs; I'll update my answer to elaborate. – A. Howells Jun 19 '19 at 16:39
  • How would distribution work with the DLLs: can I compile them into an exe or should I use an installer? –  Jun 19 '19 at 21:14
  • If you want to know about distributing SFML applications, you should probably ask another question, if it hasn't been asked already. And I probably won't be the one to answer it, because I've never actually distributed a SFML application before. That said, I believe that you *can* compile everything into one exe. The term for this is *static linking*, and you can find more detail [in the SFML FAQ](https://www.sfml-dev.org/faq.php#build-link-static). – A. Howells Jun 20 '19 at 22:21
  • One thing to keep in mind if you use an installer is that there are some extra DLLs that are included with MinGW but not default installations of Windows. Since your players probably won't have MinGW installed, you'll need to include those DLLs too. [Here's a link](https://stackoverflow.com/q/8602933/9378490) to a question where you can learn a little more about that. – A. Howells Jun 20 '19 at 22:34
0


You need Atom Packages

So, iam currently developing a new package for SFML compile on Atom. I just need to write the Docs and make it a Atom package, but take a look on the repo: https://github.com/brhaka/sfml-compiler

You can contribute to it, or just star :)

Iam working hard on it to release as soon as possible, so i suggest you to just wait a little bit. There's another package for that, but there's no documentation.

Your name is really cool!


I hope this can help you!

Brhaka

Brhaka
  • 1,622
  • 3
  • 11
  • 31
  • How would I install SFML for MinGW version 8.2.0. The most recent version I saw on their download page was for MinGW version 7.3.0. I tried to build it for my version using cmake from the source code, but that just gave the error "Error is configuration, project files may be invalid." –  Jun 18 '19 at 14:24
  • You can use [CodeBlocks](http://www.codeblocks.org/) until i release my package. You just have to install SFML, create a new project with GNU GCC Compiler (Something like that) and add SFML to build options. – Brhaka Jun 18 '19 at 14:48
  • Ok, I look forward to your package being completed. –  Jun 18 '19 at 15:04
  • Thank you dude! You can Watch, than when i release it, you'll know by email. – Brhaka Jun 18 '19 at 15:07
  • sfml-compiler is ready for Atom! You can find it at [Atom.io/packages](https://atom.io/packages/sfml-compiler). Here is the Wiki: https://github.com/brhaka/sfml-compiler/wiki – Brhaka Jun 19 '19 at 15:09
  • What do I write for the include statement? –  Jun 19 '19 at 15:22
  • If you followed the [Installation guide](https://github.com/brhaka/sfml-compiler/wiki/Installation), you didn't have to write anything on include. – Brhaka Jun 19 '19 at 15:25
  • No, in my .cpp file => #include –  Jun 19 '19 at 15:29
  • Sorry for this mistake! You didn't have to `#include` anything, just press F9 and it should compile your file. – Brhaka Jun 19 '19 at 15:34
  • When I press f9, it creates a build folder; however, it is empty. –  Jun 19 '19 at 15:40
  • Read the error log file if exists. If there are code errors, this is the problem. Otherwise, [open a new issue](https://github.com/brhaka/sfml-compiler/issues), plz. – Brhaka Jun 19 '19 at 15:43
  • Looks like this is a configuration problem. Double check if SFML is on C: and MinGW too. – Brhaka Jun 19 '19 at 15:45
  • They both are. I created a new issue which contains more information. https://github.com/brhaka/sfml-compiler/issues/1 –  Jun 19 '19 at 15:53
  • Ok. But just remember that you need to `#include` SFML classes, but nothing to run sfml-compiler. Just be sure that your code is fine. – Brhaka Jun 19 '19 at 15:55
  • [sfml-compiler](https://github.com/brhaka/sfml-compiler) is now updated and fully working. You can try [it](https://github.com/brhaka/sfml-compiler), it's really simple. – Brhaka Jun 27 '19 at 12:59