简体   繁体   中英

C++ SFML with MinGW version 8.2.0 and Atom text editor

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!

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 line 1 . 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 eg #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" (eg 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.


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM