0 ratings0% found this document useful (0 votes) 977 views22 pagesSDL On CodeLite
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
2anozo16 zsmb’s progsite
zsmb's prog site
BLOG PROJECTS ARCHIVE ABOUT
My CodeLite and SDL2 setup Hi.
6 2015.08.30. I'm acomputer
engineering student and
this site is a place for my
programming projects,
and occasionally some
posts about other things
I'm interested in.
Enjoy browsing!
Introduction Feedback
‘Awhile back | switched from CodeBlocks to CodeLite, which made Ifyou have any feedback,
setting up my programming environment a bit more complicated. you can (and please do)
While CodeBlocks came with a compiler and | could get an easy to contact me on the
install SDL1.2 package and even a project template from my first following email address:
semester programming subject's (# website, | couldn't use the zsmb13@sch.bme.hu
same in my new IDE, I spent some time figuring out how to get Updates
everything | needed set up: a compiler with C++11 and regular
expression support, a working debugger, and the ability to compile
SDL2. Here's how you can set it up too. Be warned: it's a long read.
Follow mein these places
to get notified about new
posts on the site:
With the school year starting soon, | figured this was a good time to
do a clean install of Windows 10. | only installed Windows updates
and a G4] couple things from Ninite, so everything you need to get
this setup working will be in the steps below.
W zsmb_co
Anote on the images
| decided that having every image open full size in a new tab on
click would've been inconvenient and cause too many accidental
triggers of that behaviour, so if something is too small, you'll have
to use Right click > Open image in new tab. The image sizes should
be fine on desktop though.
Installing CodeLite and Mingw-w64
Getting CodeLite is fairly straightforward, go to their @ download
page and get the stable 64 bit version (or the weekly, if you're
feeling adventurous). The CodeLite installer doesn't really have any
options, so just click through that.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip! 222anozo16 zsmb’s progsite
Weekly Build CodeLite 8.2.2 [codelite-8.3-prview] Av025 2015
05% 108 anaterounaie
CodeLite Stable Release ris:s2:0n Aug? 2018
& Cote.te RFs Fedora, openSUSE)»
The compiler I use is Mingw-w64, which you can get here.
Choose the Mingw-builds version, you'll be redirected to a
SourceForge download. This installer is a bit more complicated,
here are the options that | use:
* Version: 5.1.0
«Architecture: x86_64
+ Threads: win32
+ Exception: seh
* Build revisio
BF nsteing MinGw-wes _ x
cats
lal
me
Exeacton
Build revison 9 5
vingw-w64
By default, it installs under Program Files, but I like having the
compiler in the root directory of my drive. If you choose something
different, you'll have to pay attention and change some paths later
on.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!2anozo16 zsmb’s progsite
noe ee
Setup wil install les n the fellowina folder
Tf you would ike to inetall w86_€4-5.1.0-win32-ceh-et_v4-rev0 into a diferant
folder, click Browse end sclectanothe folie
Destination folder
CAmingw- says 64 5.1.0-wnad-eche wi-revd) Browse.
Space availabe: 210.50 65
crests shoncute in start menu
vingw-w64
bak Net = Cancal
CodeLite projects
Ihave an SDL2 project template for CodeLite that you can use, it
contains a small example program as well as the (7 SDL2 gfx library
which makes drawing simple things on the screen a lot easier. It
also links all 3 SDL libraries (you won't need them all most of the
time), and has C++11 enabled by default.
lalso have a slightly modified g++ executable template that has a
C++ Hello World program instead of the C style one that CodeLite
has by default (for some reason). You can download them both
here.
Name Description Size Date
& —codelite_projects.zip Both projects & 2015.08.30.
SDL2. C+
& codelite_sdl2_project.zip project 2015.08.20.
template
grt executable
& codelite_g++executable.zip project 2015.08.30.
template
To install them, copy their folders to C:\Program
Files\CodeLite\templates\projects (or the equivalent folder, if
you've installed it somewhere else).
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!2anozo16 zsmb’s progsite
You might be prompted to give permission to copy into the folder
(if it’s in Program Files), click Continue.
"4 Destination Folder Access Denied - x
You'll needto provide edministator permission to copy to this folder
projects
Date created: 2015-08-29 17:23
Do this forall current items
@ Continue Se
More details
Adding the compiler to Path
The easiest way to be able to use the executables and dll's that
come with the compiler from anywhere is to add the compiler's bin
folder to your Path environment variable.
Go to your compiler's installation directory, and copy the path of its
bin folder. If you installed it as | did, that's gonna be something like
C:\mingw-w64\x86_64-5.1.0-win32-seh-rt_v4-revO\mingw64\bin -
you should see files like g++.exe in this folder.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!evozmn ni poysa
Hm on ow e
+): + emmy Jo se nn a
ee | gem ans ese
met 7 es cms EE
Bem | See |e
i men tee ies
ome on oe Se
os a
= = | pe
— ee | ae
= oon os
Ea ft re
a =
Press Windows+Pause/Break on your keyboard to open the System
menu of the Control Panel (you can also do this by searching the
start menu for "System"). Click Advanced system settings on the
left.
1S Cott» Sumac Sm
Ve tic iomatin sar compe
Come
Under the Advanced tab, click Environment Variables.
hiipsizsmb.colartclesimy-codelie-and-sdi-setip!
§8 Windows 10
Pesce2anozo16 zsmb’s progsite
System Properties x
Compiter Name Hardware Acvanced System Protection Femcte
‘You must be logged on as an Admiristetor to make mest of these changes,
Perfomance
Visual effects, processor scheduling, memory usage, and vital memory
Satins |
User Pfs
Desktop setingt elated to yoursgnin
Satins. |
Statup and Recovery
Sptem stat neta fare; and Sabon orion
Settings... |
[Envronnert Varables
OK Cancel Aenly
Look for the one named Path, and click Edit.
Environment Variables x
User variables for smb
Veriable Value
oP ‘WUSERPROFILE% AppDattalLocal\Temp
7m. SWISERPROFTLE®a\AppData\Local\Temp
New. | (eat. | | Daete
system variables
Variable value “
PATHEXT
PROCESSOR_A.
PROCESSOR_ID, ¥
Paste the path you copied earlier to the beginning of all the text
that's already in the Variable value field, then add a © semicolon
after it to separate it from the rest.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!2anozo16 zsmb’s progsite
Et System Yaiable x
Varabie nar!
Varable yn sea ysieRoo apie ser oo 8)
a
eit ystem Yorable x
Nerable gore: [Path
Varable ate: — [Gi
Close all the windows you've opened by clicking OK on each.
CodeLite wizard
Now you're ready to launch CodeLite.
Codelite
Desktop app.
Search my stuff
cod|
v8.2.2
CodeLite
A Cross Platform, Open Source C,C++ and Web IDE
©2007-2015, By Eran ifrah
You'll be presented with a setup wizard on the first run. You can
choose which plugins you want on the second page of the wizard, |
usually keep all of them enabled.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip! 1122anozo16 zsmb’s progsite
Bh cusaege
BCom him
cee
Ey commousute
BL come Copngerig
center cpt een coat
1) nna Detter ote
EL omhuan Ceiteom oe
1 tteech Ayn hetatws ennai min rete
Be
2 tpt
Eaecrees
cine
2 ne ner aot
EE cineugjn cteatenmgaton
2 st Segment
EL Snot amitanetepedie exper stn
rn nes
On the next page, click Scan for installed compilers, it should
detect mingw64 automatically.
9 sen
3 tos
cb
nes
eR nes
On the last two pages, set the colour options to your liking (I'll get
to that later), as well as the whitespace settings.
Workspace
Click New Workspace on the welcome screen that you arrived at,
and select C+ from the list of languages.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!2anozo16 zsmb’s progsite
> New Workspace
& | Grete are werapace
Recent workspaces
> Forums:
Vode foume
Choose a name and path for the workspace - for the purposes of
this tutorial, just created one on my Desktop.
| New Workspace x
‘Workspace Name:
Ce
Workspace Path:
CAUsers\somb\Dektop ]
[reste the workspace under separate directory
File ame:
(CA\Users\zsmb\Desktop\C++\C++morkspace
[0K | [ Cancet |
Right click the workspace in the pane on the left, and then select
Create New Project.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!2anozo16
zambis prog site
Bice]
File Edit View Search Workspace Build Debt
Workspace View ax
Werkspace \ Explorer Tabs ¥
I (Debug
ace
Workspace Minoring >
CppCheck >
Batch insett of Copyright Bleck
CMake >
Build Workspace
Clean Wortspace
Rebuild Workspace
‘Add an Existing Project
Retag Worespace
Close Workspace
Reload Workspace
Workzpace Ealtor Preferences.
Workspace Settings.
Hello world
Under the Console category, select Simple executable (g++)
New Peja War x
feted
Tempite *
a ou
5) #F Console
Casale Cae eons!
eee
ery
ee
Se
ee
‘El Simple executable (Cobra)
A ike Executable
BF Usertemplates:
Cancel
Give the project any name you want.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!2anozo16 zsmb’s progsite
New Brject War *
Panna
Projectrame: [hell
Project peths | C\Uzer\zsmé\Desidop\C-= Browse.
create the project under 2 ceparate directory
(c\User\zema\Derttop\C=+\hello\hete project
“Back Net Gnesi
The Compiler and Debugger should both be set by default.
New Project Wizard ¥
ere
lect the project toolchain
Compiler | MinGW (ningn64) =
Debugger. GNU go debugger x
2 Back Firizh Cancel
In the pane on the left, open the project by toggling the arrows,
then open the src folder inside. Double clicking the main.cpp file
will open it in the editor.
ee
Vint
You can build and run your selected project (indicated by bold
letters in your workspace) by pressing Ctrl+F9, or from the menu
under Build > Build and Run Project.
Getting SDL2
hiipsizsmb.colartclesimy-codelie-and-sdi-setip! se22anozo16 zsmb’s progsite
Ifall that ran fine, you can move on to getting SDL. You'll want to
get the mingw Development Libraries of all of the SDL libraries.
+ GSDL2 the core components of the library
+ G@SDL2_image for using image files
* G@SDL2_mixer for using audio
+ GSDL2_ttfto render fonts
SDL )
i] SDL version 2.0.3 (stable)
Source Code
Runtime Binaries:
ira uss 22686 (2-0 Won)
Development Libraries:
Here's what the SDL_image site looks like, the last 2 have identical
layouts to it.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!
0222anozo16 zsmb’s progsite
SDL_image 2.0
soLiowe12
Author:
Sam Lantinga and Mattias Engdegard
Documentatior
ttp://jcatksino-ip.org:8080/SDL_image/ and on this site
Source:
SDL? image-2.0.0.zip
Mercurial Repository
hitp:/+he-tibsdl.or#/SDL_ image
Runtime Binaries:
‘Windows
SDIL2 image-2,0,0-win32-x86.zip (32-bit Windows)
SDL2_image-2.0.0-win32-x64.zip (64-bit Windows)
‘Mac OSX,
SDL2_image-2.0.0.dmg (Intel 10.5+)
Linux
Please contact your distribution maintainer for updates.
Development Libraries:
Windows
SDL2
VC.zip (Visual C+
(64-bit)
‘Mac OS X.
SDL2_image-2,0,0.dmg (Intel 10.5+)
Linux
Please contact your distribution maintainer for updates,
iOS & Android
Projects for these platforms are included with the source,
The downloaded archives will have a x86_64(...) folder inside, you'll
have to copy the contents of those folders (bin, include, lib, share)
into your compiler's root directory, which is C:\mingw-w64\x86_64-
5.1.0-win32-seh-rt_v4-revO\mingwe4 if you chose the same
installation path as | did.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!
ra2anozo16
a et tasting
Hello SDL2
Ifyou still have CodeLite running after the hello world example, you
might have to restart it at this point for it to pick up all the new
files.
Create a new project, name it whatever you want, and then under
the GUI category, select the SDL2 C++ project (which should be here
if you copied the template to the right directory).
hiipsizsmb.colartclesimy-codelie-and-sdi-setip!2anozo16 _zsmb's prog site
Workspace Mirroring >
v Bac
i CppCheck >
Bi mainccpp
Batch Insert of Copyright Block:
CMake >
Bulle Workspace
Clean Workspace
Rebuild Workspace
‘Add an Baiting Project
Retag Workspace
Close Workspace
Reload Workspace
Workspace Editor Preferences...
Workspace Settings.
|New Bejact Winer *
tonne
Templste “
5 ou
B waWdige's GUI Application (woFrame, using wxCrafter)
Woawesdi ehcamts ae cee
oe
eae
ae
Roe es
aoe cere
Bie Nees Greil |
The compiler should be selected by default again, click Finish to
create the project.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!2anozo16 zsmb’s progsite
New Project Wars
for
Compiler MinGW (eningn64)
Debugger [GNU gio debugger
eack | | Finioh
Caneel
Inside the project you'll find a SDL_gfx folder, which you should not,
touch unless you know what you're doing. You can double click
main.cpp in the src folder to view the code of the sample SDL
project.
You can make this project active by double clicking its name in the
workspace (if you forget to select
project in the next step).
‘ll compile your previous
om
iis helio
\ iit hello sal
© include
[Bh SDL. gh //do not modity
v Bsc
i maincpp
Now you should be ready to compile and run it, so press Ctrl+F9. If
the circles appear, you have successfully set up everything.
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!
1222anozo16 zsmb’s progsite
Note that if you have a different install path for your compiler,
you'll have to go into the project settings (right click on the project,
Settings), and modify the paths you see under the Compiler and
Linker menus accordingly before you can compile the project.
Acommon SDL2 bug
If you're getting an error that has something to do with
“winapifamily.h" when trying to compile, check out 3 this thread
for the solution (you have to download a file and put it in your SDL
installation directory).
Break
At this point, your installation and setup is basically complete, so
you can stop reading here. In the following I'll show you how my
syntax highlighting is set up and some additional tests (debugger,
regular expressions, C++11 features) that | run for myself, but those
aren't exactly necessary.
Theme
luse a theme that's no longer available in CodeLite and | also
slightly modified it to my taste. You can download it below, and
here's how you can set it up.
Name Description Size Date
Apack of Codelite 152
themes Kp 2025.08.30
& codelite_themes.zip
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip! wee2ari2n16 25mbs prog site
Go to Settings > Colours and Fonts.
Settings PHP Help
Global Editor Preferences.
es
Keybeard shortcuts
Environment Variables. Ce-sitt-v
Build Settings.
GDB Settings
Code Completion
LLDB Settings.
Click the Import settings icon (third one on the top), and browse for
the downloaded zip file
WS can aneFents
‘Bae
ban: Selle
bared lw [Beck Eo
cient oles [white i
For the Global theme setting, choose Code::Blocks Dark, which
should now be in the list.
1S Gansta
1 Bae:
ban: aie
Getter [Rana
fascia fen Caoucd
sugar [Bi gars
lve
That's it, you're done!
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip!
swe2anozo16 zsmb’s progsite
Hello debugger
| used to do this test to check if my debugger's working (CodeLite
and my previous compiler had some issues with its path settings),
but since | use Mingw-w64 this is just an extra test.
Create a new project, choose Console -> Simple executable (g++
New Brject War *
tonne
project temple from the fst be
Templte “
@ oul
5 8 Console
2 waWdigets Console Application (with vxEvent loop)
‘Simple eecutabe (maWidgets enabled)
es
A ike Executable
$8 Usertemplates:
Nee Cancel
Open main.cpp and copy this code into it.
include
int main() {
std::cout << "Hello, world!" << std::endl;
int* p = NULL
int ¢ =a + 3*b + (*p)s
std::cout << 2% << std:tendl;
return @;
hiipsizsmb.colartclesimy-codelie-and-sdi-setip! 9222anozo16 zsmb’s progsite
Ifyou run this (Ctrl+F9), it should crash, since you're trying to
dereference a NULL pointer on line 10.
To start the debugger, press F5 or select Debugger >
Start/Continue Debugger from the menu
Debugger Plugins Perspective Settings PHP
Restart Debugger Ctr Shitt-F5
Attach to process
Debug a core dump.
Pa
debugger
Stop debugge Shift-F5
Step Into Ft
Net
Nest Instruction
Step Out
Show Cursor
Toggle Breakpoint Fo
Disable
En
Al Breakpoints
All Breskpoints
te All
Quick Debug
GB Windows >
In the popup window that appears, choose Build and Debug.
Codelite x
@ wesou terete prea oe dugg
ClRemembermy answer and dont ask meagain
[Build end Debug Debug
The debugger should find the segmentation fault.
hiipsizsmb.colartclesimy-codelie-and-sdi-setip! ze2anozo16 _zsmb's prog site
CodeLite x
Program Received signal SIGSEGV
Stack trace is available in the ‘Call Stack’ ta
Itwill show you the line where the crash occurred, and you can
ook at information like the call stack or the current values of local
variables in the Debugger pane.
Hello regex
Regular expressions are still a bit new to GCC (on Linux, | still have
to compile them with g++-4.9 instead of just g++), thankfully
Mingw-w64 has them implemented already.
Create a new g++ executable, and open the project settings. In the
Compiler section, add ";-std=c++11" to the C+ Compiler Options
that are already there. (This flag is added in the SDL2 project by
default.)
= z
= ————
ees rene Sens =
cove SN ory Bl
i ee nn
mejPaitalicomesscoanlaonne
pty cP o
Po amples oer eit
(Compt pine
C=] Cee] Ee [ee |
Here's the example code that | use for testing:
include
include
#include
void test(std::string str) {
std::regex exp("a.*")5
if(regex_match(str, exp)) {
std:icout << "Matched!" << std::endl;
hiipsizsmb.colartclesimy-codelile-and-sdiZ-setip! 2222anozo16 zsmb’s progsite
else {
std::cout << "Not matched!" << std::endl}
int main() {
stdiistring strings[] = ("abc"
for(auto str: strings) {
test(str);
The regular expression "4a.*" matches any string that starts with an
"a" (it matches an "a" at the beginning of the string, and then any
number of any characters). Running the test function against the
strings will of course match 2 of the 4.
Notice how the example also uses a range-for loop and the auto
keyword for going through the array of strings, which are also
C++11 features.
The end
Well, that's it for now. if you get stuck anywhere, feel free to contact
me, all the info for it isin the sidebar. Hope it worked out for you,
and thanks for reading.
This website is hosted on a If Raspberry Pi
hiipsizsmb.colartclesimy-codelie-and-sdi-setip! zane