Hello again!
In this video, we are going to look at how to configure a compiler to work with SFML.
I am going to assume that you have successfully downloaded the binaries for your system and your compiler,
and you know where to find them. To get the compiler to use SFML,
we need to give it some information.
We need to tell it where to find the headers for SFML, where to find the library files for
SFML.
And also, which of these library files we actually want to have built into the program.
If you are using a command line on a Unix system, you'd probably have something like this. Minus capital 'I',
then the directory with the headers. Minus capital 'L', then the directory with the libraries, and then, minus 'l and
the library name, for each of the libraries that you want.
So I am actually doing this in MinGW, on Windows.
So there is where I installed my SFML.
The headers are in the include directory underneath
that. The library files are in the "lib" directory.
And then I have these three libraries that I want to build into my program.
And then if I run it...
Now, if this was a Unix system, then the program would be able to work out where the shared objects
are, and load them up when it starts.
As this is Windows, the shared objects have to be in the same directory as the program binary.
So I need to copy them. And they are in the "bin" directory in my installation.
And then - there we are.
So there is my basic window, and it is very basic!
It does not do anything, but it is a start.
If you are using an Integrated Development Environment, then the basic principles are the same,
but the actual details are going to vary. Which dialogue box you have to click on, which field you have to
edit, and
so on. It will depend on the actual editor. But generally there will be something like "Additional Include
Directories", where you put the path for the headers, "Additional Library Directories", where you put the
path to the libraries, and then "Additional Dependencies", where you put the library files.
As an example, I am going to use Visual Studio.
I will go through the code in the next video.
So do not worry, if you do not understand it. I will give you the code as a downloadable resource for this
video, if you want to try it out for yourself.
So we need to go into the project properties. And then, for "C++, General", we need to add the path to
the headers, as an additional include directory.
And then for the "Linker, General", we need to add the path to the library files as an additional library
directory. In the "Input", the "Additional Dependencies", we put the libraries that we want to use.
I have added "sfml-main" here, because you might get a warning about not having "WinMain" defined.
And if you get that, then that is how to get rid of it.
So let's try that out.
Right.
So we get an error: "the machine type conflicts with the target machine type".
So I think that means we are mixing 32 and 64 bits.
So let's change that to 64 bits. Then clean the build. Always clean the built after you change any of the
properties.
And then. Right. That compiles, but it cannot execute, because it cannot find the shared objects, the
DLL's.
So again, we have to copy them.
So we need to go to the "C" drive. Usually. Then "users", then your username, then "source", and then "repos".
And then in the project directory. And we are using x64, and then "debug".
Right.
So that is the actual directory where the program binary is.
Then we have to go to our SFML installation, into the "bin" directory. And then to copy all the DLL's, from
this directory into the program executable directory.
And then let's see if it works.
Oh dear!
Now, the program has been aborted.
And by the way, I do actually know how to do this.
I am just trying to show some of the things that can go wrong.
So going back into the project properties.
These are actually the release versions of the shared libraries, but we are actually running it in a debug build.
So we need to use the debug versions.
So these need to have minus "d" after the name.
"main" minus "d", system
minus "d" and window
minus "d".
And at last, there it is!
So as I said, I will go over this code in the next video.
I will also give you this source code and the instructions for installing on Visual Studio, as a downloadable
resource.
That is it for this video, but I will see you next time.
Until then, keep coding!