IntroductionTo start off let's recap on what SFML and CodeLite are. SFML is a graphics library for C++ that is designed to be simple. SFML stands for Simple and Fast Multimedia Library. CodeLite is a IDE. IDE stands for intergrated development environment. In simple terms an IDE is a editor for code that has special tools to help you develop faster. CodeLite is open-source, cross-platform. First of all I'll go over installing CodeLite, CodeLite is only supported on these operating systems so make sure one of them is yours:
Windows 7
Windows 8
Windows 8.1
Windows 10
Debian / Ubuntu
Fedora / OpenSUSE
ArchLinux
Mac OSX 10.8 and later
FreeBSD (this has no installer)This tutorial is designed for SFML 2.3.1 and CodeLite 8.1.
Installing CodeLite 8.1Lets start installing CodeLite 8.1. Go to
http://downloads.codelite.org Select a package depending on what OS your on and whether your 64bit or 32bit. I'm Windows 64bit. We will be selecting a "CodeLite Stable Release". So I'll be clicking on CodeLite 8.2.0 for Windows 64 bit Installer Direct Link | SourceForge. Click Direct Link. It should start downloading and once it has downloaded run the .exe. From there it's just the basics of installing programs.
Downloading SFML 2.3.1Okay, now lets download SFML now that we have CodeLite. Head over to
http://www.sfml-dev.org/download/sfml/2.3.1/. You can see there's tabs with: Windows, Linux, Mac and All. The "All" tab contains the source code. We will be downloading the pre-made SFML folder though. Select a tab depending on your OS. Then select a version depending on whether your 32 bit or 64 bit. I'm on Windows 64 bit. If your on WIndows your going to want to download "GCC 4.8.1 TDM (SJLJ)". Ignore the 4.7.1 version. Click on "Download". Once SFML 2.3.1 has download you will get a .zip folder. Open it up and you should see a folder in it called SFML 2.3.1. Drag that folder to your C: drive. You should end up with SFML 2.3.1 in the C: drive next to folders with names like Program Files and Users. If this is true then you have correctly downloaded SFML 2.3.1.
Creating a project in CodeLiteNow you may be thinking you can just open CodeLite and start writing majestic code! Sadly that's not true. What your going to want to do is open up CodeLite 8.1. You should see a main view with tabs such as "New Workspace", "Open Workspace", Forums", Wiki". Click on "New Workspace". Select C++ and click OK. Now you can select the location and name. I set my location in my documents folder. So my "Workspace Path" is:
C:\Users\[username]\DocumentsNow you want to select a workspace name. I set mine as "CodeLiteProjects". Enable "Create the workspace under a separate directory". Then click OK. Now you want to create a project to use SFML out. Click on "File" at the top left of the CodeLite window. Then click "New" and then "New Project". You will see a window pop up with a green box saying "New Project". Below that there will be the word Template then tabs called things like "GUI", "Console", "Others". Click on the plus sign next to "Console". It should expand out to reveal more things. Select "Simple Executable (g++)" and then click "Next >". Now you will see another window with the word "Project Name" and "Project Path". Don't edit Project Path, that is correct by default. For project name enter anything you want. I'll enter "SFML-Demo". Make sure "Create the project under a seperatre directory" is enabled. Then click "Next >".
There should be one last window with the word's "Compiler" and "Debugger". Presuming you have Mingw installed these will by default be correct. Just click "Finish".
Running SFML 2.3.1 in CodeLiteOkay, now we are on the last part! All we need to do is make sure CodeLite knows where SFML 2.3.1 is downloaded to. You should have a project in the "Workspace View" under "CodeLiteProjects". There will be a arrow to the left of the name of your project. Click that to expand the project. Do the same for a folder called "src". Now double click on "main.cpp".
By default main.cpp will have some random stuff in. On the top of the CodeLite window there will be a tab called "Build" click that then click "Run". It will ask you whether you want to build. Say yes and then it should run. It should open a console window with the output "hello world". Close that window. Now we know CodeLite is compiling correctly.
All we have to do now is tell CodeLite where to find SFML 2.3.1. In the workspace view you have your project name. Right click on it. At the bottom of the opened bit there will be Settings. Click on that. Now we see the project settings. There's a few tabs on the left. Click on "Compiler". In the center of the new window you will see text saying "Include Paths". Next to that is a text box. Remember when you downloaded and moved SFML 2.3.1. I download it to the C: drive. So enter in that text box "C:\SFML-2.3.1\include". That is just saying to CodeLite to go to a folder in SFML called include and look at the files in that. Below that text box is another called "Preprocessors". Write in that "SFML_STATIC". Now click on "Linker" on the tabs at the left of the window. You will see a text box called "Libraries Search Path". Enter "C:\SFML-2.3.1\lib". That tells CodeLite to open the files in the SFML folder in the the lib folder. Below that is a text box called libraries. Click the "..." to the right of it. A window will pop up. In that write this:
sfml-graphics
sfml-window
sfml-audio
sfml-network
sfml-systemNow your nearly done! Click "OK" and you should return to the main window. Edit the main.cpp file and enter:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Majestic Window");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
}
window.display();
}
}Getting the DLLsNow if you click "Build" and then "Run". You will be so happy! Then you get annoying popups with called System Error saying they can't find SFML files. How annoying! To fix this we need to add the SFML .dll files to the same directory as our project. Open up where you downloaded SFML (C:\SFML-2.3.1\bin) to and then navigate to the bin folder in that. Copy all the files in that. Then go to where your CodeLite project is (C:\Users\[username]\Documents\CodeLiteProjects\SFML-Demo). There should be a folder called "Debug". Go there and paste all the files. If you run the project now it will return more errors saying about more .dll files. Go to where you installed Mingw. In my case I had CodeBlocks with Mingw installed so it was at "C:\Program Files (x86)\CodeBlocks\MinGW". You should see a bin folder click on that. There's a LOT of files. Look for two dll's. Called
libstdc++-6.dll and
libgcc_S_sjlj-1.dll. Copy them both into the your SFML project's debug folder. If you run the project now it should work!
Finish!Now, your finished getting SFML 2.3.1 to work with CodeLite 8.1. Go build some amazing SFML applications!