Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I share my SFML game with others without errors?

So, I finished a game in C ++ / SFML and I would like to send it to someone but when I send it there are errors: I tested the exe on another computer with SFML DLLs required and it shows me that libstdc ++ - 6.dll is missing, so I added it and I tried again and it tells me that there are still other dll missing, it is very embarrassing. How can I share my game without all those errors and missing DLLs?

like image 481
Enchant3d Avatar asked Jun 14 '19 16:06

Enchant3d


People also ask

Is SFML portable?

SFML is a simple to use and portable API written in C++.

What games are made with SFML?

Chesster, puzzle game. Cosmoscroll, free open-source space-based shoot 'em up game. Crea, moddable 2D sandbox game. Extreme Tux Racer, free open-source arctic racing game featuring Tux (using SFML since version 0.7).

Is SFML a graphics library?

Simple and Fast Multimedia LibraryIt is composed of five modules: system, window, graphics, audio and network.


3 Answers

You could use Dependency Walker (depends.exe) to find all the dll-s your application is using. It will still require some trial and error cycles to discover the ones you need, but at least you have somewhere to start from. You will most likely need the dlls provided by the compiler and the dlls of additional libraries you are using. You will most likely not need anything from the System32 folder.

like image 129
Marko Mahnič Avatar answered Oct 06 '22 14:10

Marko Mahnič


If you're planning on deploying an SFML application, statically building your project is recommended. This requires also statically building SFML. It takes a little time to setup, but all dependencies will be included in your executable making your application much more reliable and easier to install. This process is not to be confused with statically linking to SFML, which you will still need to do once you've statically build SFML.

You will have to clone the SFML repository and use CMake to generate your visual studio project that will then let you build SFML statically with /MTd for debug and /MT for release. These options can be found in Project Properties > C/C++ > Code Generation > Runtime Library.

like image 44
aj.toulan Avatar answered Oct 06 '22 15:10

aj.toulan


As @aj.toulan said, you need to Link SFML statically. I will assume you're developing on Windows using Visual Studio. When you download and setup SFML, it already has static libraries built.

If you are using any external libs you need to build a static version of them!

You need to add a pre-processor definition for SFML_STATIC in your Project Properties.

  1. Go to Project Properties
  2. Go to tab C/C++
  3. Preprocessor
  4. Add "SFML_STATIC;" at the start of Preprocessor Definitions and press Enter.
  5. Apply

Now you need to include static libraries. Whichever SFML libraries you are using in your project but you add "-s"

Eg #pragma comment(lib,"sfml-graphics-s.lib")

SFML uses openal32.lib and due to licensing, you will need to have that DLL in the folder with your exe

#ifndef SFML_STATIC
#pragma comment(lib,"sfml-graphics-s.lib")
#pragma comment(lib,"freetype.lib")
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"sfml-system-s.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"sfml-window-s.lib")
#pragma comment(lib,"gdi32")
#pragma comment(lib,"winmm")
#pragma comment(lib,"sfml-audio-s.lib")
#pragma comment(lib,"flac.lib")
#pragma comment(lib,"ogg.lib")
#pragma comment(lib,"vorbisenc.lib")
#pragma comment(lib,"vorbisfile.lib")
#pragma comment(lib,"vorbis.lib")
#pragma comment(lib,"openal32.lib")
#pragma comment(lib,"sfml-main.lib")
#pragma comment(lib,"sfml-network-s.lib")
#pragma comment(lib,"ws2_32.lib")
#pragma comment(lib,"openal32.lib")
//include below line if you want to hide console window
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#endif // !SFML_STATIC

Link to SFML FAQ showing what you need to include for each lib when linking statically

like image 1
Glucio Avatar answered Oct 06 '22 16:10

Glucio