VS2010 template project?

Making those links to SFML are really annoying and I was wondering If I could make another project and link it to SFML and use that as a template project that I could select as an option when making a new porject.
You can do what I do and make your own header.


I just name it sfml.h and put it in the same folder as the SFML include subdirectory. Then all I have to do is #include <sfml.h> and it will include all of it. The #pragmas cover linking to the libs.

Note I also default to static linking because dynamic linking in Windows is dumb, IMO.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

#pragma once
#ifndef SFMLFULL_INCLUDED
#define SFMLFULL_INCLUDED

#ifndef SFML_STATIC
#define SFML_STATIC
#endif

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

#if defined(_DEBUG) || defined(DEBUG)
    #if defined(SFML_STATIC)
        #pragma comment(lib,"sfml-graphics-s-d.lib")
        #pragma comment(lib,"sfml-audio-s-d.lib")
        #pragma comment(lib,"sfml-network-s-d.lib")
        #pragma comment(lib,"sfml-window-s-d.lib")
        #pragma comment(lib,"sfml-system-s-d.lib")
        #pragma comment(lib,"sfml-main-d.lib")
    #else
        #pragma comment(lib,"sfml-graphics-d.lib")
        #pragma comment(lib,"sfml-audio-d.lib")
        #pragma comment(lib,"sfml-network-d.lib")
        #pragma comment(lib,"sfml-window-d.lib")
        #pragma comment(lib,"sfml-system-d.lib")
        #pragma comment(lib,"sfml-main-d.lib")
    #endif
#else
    #if defined(SFML_STATIC)
        #pragma comment(lib,"sfml-graphics-s.lib")
        #pragma comment(lib,"sfml-audio-s.lib")
        #pragma comment(lib,"sfml-network-s.lib")
        #pragma comment(lib,"sfml-window-s.lib")
        #pragma comment(lib,"sfml-system-s.lib")
        #pragma comment(lib,"sfml-main.lib")
    #else
        #pragma comment(lib,"sfml-graphics.lib")
        #pragma comment(lib,"sfml-audio.lib")
        #pragma comment(lib,"sfml-network.lib")
        #pragma comment(lib,"sfml-window.lib")
        #pragma comment(lib,"sfml-system.lib")
        #pragma comment(lib,"sfml-main.lib")
    #endif
#endif

#endif // SFMLFULL_INCLUDED 
I already tended to use static libraries to avoid as many dll's as possible, but why is dynamically linking libraries dumb? Besides that, thank you for the advise.

So when I actually start coding and I #include <sfml.h> do I just write:

#DEFINE DEBUG

then #DEFINE SFML_STATIC if I want static libs, or leave out the line if I want debug?

And if you #DEFINE SFML_STATIC then you will get the standard libs?
Dischs solution is nice, but to answer your question you can't exactly make a project template for unmanaged c++. What you would need to do is create a custom project wizard. I actually already made one for SFML http://code.google.com/p/sfml-project-wizard/
but why is dynamically linking libraries dumb?


It's personal opinion. But my logic is as follows:

1) Nobody (or at least very few people) have SFML installed on their system already, so if you want your program to work, you have to bundle the DLL with your exe when you distribute it anyway.

2) Even if they already do have sfml on their system, it might be a different version and therefore incompatible with your exe... so you'd still have to distribute the dll with the exe

3) The combined filesize of the dll + exe will be larger than just the statically linked exe

4) There's more risk of the user misplacing the dll and/or replacing it with an incorrect version of of the dll. If it's statically linked the risk is zero.

5) It contributes to the user's computer getting riddled with dozens of copies of sfml dlls.

6) Statically linking allows for possible optimizations that dynamically linking does not.


Note that most of these problems are due to the way Windows handles shared libs (ie: it doesn't really). On other platforms (for example, many Linux distros), shared libs are common because there's support for managing them built in. In those cases, the opposite is true, and dynamically linking is preferred.


But yeah... on Windows... save yourself and your user some headaches and just statically link.


So when I actually start coding and I #include <sfml.h> do I just write:

#DEFINE DEBUG


No. Do not #define DEBUG. MSVS does this automatically for debug builds. The reason those #ifdefs are in there is so that the header can identify whether it's a Debug or Release build, and link to the appropriate build of SFML.

then #DEFINE SFML_STATIC if I want static libs, or leave out the line if I want debug?


The header already kind of #define's SFML_STATIC. If you want dynamic libs, you'll have to comment out or delete lines 6-8 of that header.

or leave out the line if I want debug?


Statically linking has absolutely nothing to do with debugging. Don't worry about debug/release stuff. MSVS will do that automatically. The only option you really have here is static vs. dynamic linkage.

If you want static:
- do nothing. The header is already set up for statically linking.

If you want dynamic:
- comment out or delete lines 6-8 of that header.

Once you make that decision... all you have to do is #include <sfml.h> . Nothing more.
Last edited on
Topic archived. No new replies allowed.