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

烂漫一生 提交于 2019-12-22 08:19:25

问题


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?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


You should test the executable with all the compiler DLLs.

libstdc++-6.dll is a DLL file that is in the compiler's folder. So you should test it with all the compiler's dlls.

Hope this works.



来源:https://stackoverflow.com/questions/56602222/how-can-i-share-my-sfml-game-with-others-without-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!