setting up sfml

喜欢而已 提交于 2019-12-11 13:16:07

问题


I'm following the sfml getting started guide for version 2 and codeblocks and did everything the tutorial told me to do :

  • downloaded and unzipped the sdk

  • added the path to the sfml headers and libraries

  • linked the libraries graphics, window and system

but the sample code doesnt work. I'm getting the error message that sfml-graphics-d-2.dll is missing. Compilation works, the window opens but remains black and this error pops up. Here's the link to the tutorial http://www.sfml-dev.org/tutorials/2.0/start-cb.php

Since Im new to c++ and codeblocks, I would be grateful for a detailed answer.

UPDATE: I have copied the SFML dlls to the executable. Now my program just crashes. I don't know why. It's the exact same code as used in the tutorial.

UPDATE: I have changed the linked libraries to the -s version and added the #define SFML_STATIC. The program still builds and then crashes


回答1:


If you're using the latest Code::Blocks version, which includes GCC 4.7.1, then you have to recompile SFML on your own (or use my Nightly Builds), because the ones provided are only for GCC versions < 4.7.x.




回答2:


It seems you aren't setting up your static libraries to be built inside the project, and instead using dynamic linking with your SFML. I had a similar problem when setting up SFML a couple months ago, recall this quote:

The settings shown here will result in your application being linked to the dynamic version of SFML, the one that needs the DLL files. If you want to get rid of these DLLs and have SFML directly integrated to your executable, you must link to the static version. Static SFML libraries have the "-s" suffix: "sfml-xxx-s-d" for Debug, and "sfml-xxx-s" for Release. In this case, you'll also need to define the SFML_STATIC macro in the preprocessor options of your project.

make sure you include the static files in your project

sfml-graphics-s-d //for debug
sfml-window-s-d   //d for debug!
sfml-system-s-d

for release, omit the d (sfml-graphics-s)

Next go to Compiler settings -> #Defines and type

SFML_STATIC



回答3:


Regarding Visual Studio 2017 and SFML-2.5.1, I suggest this tutorial. Setting up SFML is similar to setting up SDL, GLFW, freeGLUT, and GLEW, with two peculiarities: .lib files are 29, and .dll are 11. Briefly I suggest:
1. Upload SFML and select first "Download". Copy downloaded folder and paste in a folder you created in C:.
2. Create Empty Project.
3. Configure "Additional Include Directories" with C:...\SFML-2.5.1\include.
4. Configure "Additional Library Directories" with C:...\SFML-2.5.1\lib.
5. In "Additional Dependencies" window copy and paste: flac.lib; freetype.lib; ogg.lib; openal32.lib; sfml-audio.lib; sfml-audio-d.lib; sfml-audio-s.lib; sfml-audio-s-d.lib; sfml-graphics.lib; sfml-graphics-d.lib; sfml-graphics-s.lib; sfml-graphics-s-d.lib; sfml-main.lib; sfml-main-d.lib; sfml-network.lib; sfml-network-d.lib; sfml-network-s.lib; sfml-network-s-d.lib; sfml-system.lib; sfml-system-d.lib; sfml-system-s.lib; sfml-system-s-d.lib; sfml-window.lib; sfml-window-d.lib; sfml-window-s.lib; sfml-window-s-d.lib; vorbis.lib; vorbisenc.lib; vorbisfile.lib
6. Navigate to C: > ... > SFML2.5.1 > bin. Copy all 11 dll files and paste in project-folder.

Good job. Regards.



来源:https://stackoverflow.com/questions/14056999/setting-up-sfml

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