SDL2 With Eclipse on Fedora22

On a Fedora22 system with Eclipse Mars version 4.5.1 this worked for me.

  • Create a new C++ project (File > New > C++ Project). 
  • You will need to pick a toolchain - Linux GCC.

If you want to use C++11 do the following:

  • Right click your Project under “Package Explorer” and select Properties.
  • Select (C/C++ Build > Settings > GCC C++ Compiler > Dialect)
  •  Under “Language standard” select: "ISO C++11 (-std=c++0x)". Click Apply, then OK.

Configure Eclipse to use SDL2

At this step, I'd suggest to use the system's terminal/shell to find out or verify the existence/location of the necessary files/libraries for SDL2 on your system. 

First, if you want to find the location of the necessary libraries on your system, executing the following in the terminal will provide you with the "include" location and other compiler/preprocessor flags

$ sdl2-config --cflags

Similarly, to list the libraries/linker-flags

 $ sdl2-config --libs

For example, on my Fedora22 (64bit) system, the output looks like this

$ sdl2-config --cflags --libs
-I/usr/include/SDL2 -D_REENTRANT
-lSDL2 -lpthread


You can test the compilation in a separate temporary directory without the eclipse-related project files--i.e. only the source files--like this:

$ mkdir /tmp/testing
$ cp -r main.cpp error.cpp lesson45.cpp /tmp/testing/.
$ cd /tmp/testing
$ g++ `sdl2-config --cflags --libs` -o lesson45 main.cpp error.cpp lesson45.cpp


Now, to use the SDL2 libraries/paths within Eclipse, add the necessary libraries from the `sdl2-config --libs` output

  • Right click your Project under “Package Explorer” and select Properties.
  • Select (C/C++ General > Paths and Symbols > Libraries)
  • Click “Add” and type `SDL2` and click OK
  • Click “Add” and type `pthread` and click OK

To add the preprocessor directive from the `sdl2-config --cflags` output

  • Right click your Project under “Package Explorer” and select Properties.
  • Select (C/C++ Build > Settings > GCC C++ Compiler > Preprocessor)
  • Under "Defined symbols (-D)", Click the "Add" icon
  • Type `_REENTRANT` and click OK

Resources

Popular posts from this blog

Password Policy in RHEL 7

Centos 7 pulseaudio

Password Aging and Authentication in RHEL7