官术网_书友最值得收藏!

Resources and installation

You can download the latest stable pre-built version of the library at: latest Git revision and compile it yourself from here: for beginners. You have to wait for major versions to be released, however they're more stable. To build SFML yourself, you will need to use CMake, which is a tool used to generate solutions or g++ Makefiles, depending on the software that will be used to compile it. The official SFML website provides tutorials on building it yourself at: http://www.sfml-dev.org/tutorials.

After either obtaining the pre-built version of SFML or compiling it yourself, it's a good idea to move it somewhere more permanent, hopefully with a short path. It's not unusual to dedicate a directory somewhere on your local drive that will hold SFML and potentially other libraries, which can be linked to quickly and at all times. This becomes useful when dealing with several versions of the same library as well. For the rest of this book, we will assume the location of our SFML library and header directories to be at C:\libs\SFML-2.3, consequently being C:\libs\SFML-2.3\lib and C:\libs\SFML-2.3\include. These directories have to be set up correctly in your compiler of choice for the project to build. We will be using Microsoft Visual Studio 2013 throughout the course of this book, however instructions on setting up projects for Code::Blocks can be found in the tutorials section of the SFML website.

Setting up a Microsoft Visual Studio project

Create a new solution in your IDE. It can be a Win32 application or a console application, which is not really relevant, although a nice console window is often useful for debug purposes. I always go with the Empty Project option to avoid any auto-generated code. After that's done, let's prepare our project to use SFML:

  1. Navigate to the VC++ Directories underneath Configuration Properties by right clicking on our project and selecting Properties.
  2. Only two fields are of any concern to us, the Include Directories and Library Directories. Make sure the paths to the SFML library and include directories are provided for both Debug and Release configurations.
  3. When linking SFML statically, the Preprocessor section underneath C/C++ is where you need to define the SFML_STATIC macro.
  4. Next is the Additional Library Directories in General underneath Linker. Make sure that it also points to the SFML library directory in both debug and release configurations.
  5. Lastly, we need to set up the project dependencies by editing the Additional Dependencies field in the Input section underneath Linker. It would look something like this for the debug configuration when using statically linked libraries: sfml-graphics-s-d.lib; sfml-window-s-d.lib; sfml-system-s-d.lib; opengl32.lib; freetype.lib; jpeg.lib; winmm.lib; gdi32.lib;

    Remember that we need to include the system library because of library dependencies. Also note the use of -s and -d postfixes. Make sure both debug and release configurations are set up and that the release configuration omits the -d postfix.

主站蜘蛛池模板: 长丰县| 新津县| 上饶市| 乌鲁木齐市| 浦县| 积石山| 神池县| 北京市| 海门市| 正镶白旗| 临安市| 湘潭市| 谢通门县| 临桂县| 河间市| 泸定县| 临清市| 丰原市| 綦江县| 蒙阴县| 大厂| 新民市| 望城县| 佛坪县| 莫力| 浮山县| 固原市| 临邑县| 内乡县| 山东省| 东乌珠穆沁旗| 颍上县| 丽江市| 拜泉县| 犍为县| 平江县| 金乡县| 耿马| 牙克石市| 萍乡市| 沙洋县|