How use the SDL library


#1

Hi everybody
I am beginner in programming, I am doing a training.
I would like use the SDL library with cloud9 IDE, someone know if it is possible and if yes how I can process.

#include <SDL/SDL.h>

thanks


#2

Which programming language are you planning to use? I assume C or C++

You can install SDL library in your workspace using the following commands:

sudo apt-get install libsdl2-2.0

sudo apt-get install libsdl2-dev

To learn how to use the library, you should read some of the tutorials listed in the library’s official site:

http://wiki.libsdl.org/Tutorials


#4

Thank you for the answer and you true it is for the C.
when i use your commands on the terminal, I receive some errors:

greg06:~/workspace sudo apt-get install libsdl2-2.0 Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package libsdl2-2.0 E: Couldn't find any package by regex 'libsdl2-2.0' greg06:~/workspace

and
greg06:~/workspace $ sudo apt-get install libsdl2-dev
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package libsdl2-de

could you help me ?

Thanks


#5

Sorry, I forgot to say that you probably need to run this command first:

sudo apt-get update

Then install the libraries.


#7

Thank you again Bigchief,

I am sorry, but I am beginner in C and totally noob in Linux.

But, when I call the library with #include<SDL/SDL.h> , I receive this messsage :

    Running "/home/ubuntu/workspace/TestLibrary.c"
/home/ubuntu/workspace/TestLibrary.c:3:21: fatal error: SDL/SDL.h: No such file or directory
 #include <SDL/SDL.h>
                     ^
compilation terminated.


Process exited with code: 1

#8

This is what happen when I use your commands :

greg06:~/workspace $ sudo apt-get install libsdl2-2.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libsdl2-2.0-0' for regex 'libsdl2-2.0'
The following package was automatically installed and is no longer required:
  gcc-4.8-base:i386
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
  libegl1-mesa libegl1-mesa-drivers libgbm1 libopenvg1-mesa
  libwayland-egl1-mesa libwayland-server0 libxcb-xfixes0
The following NEW packages will be installed:
  libegl1-mesa libegl1-mesa-drivers libgbm1 libopenvg1-mesa libsdl2-2.0-0
  libwayland-egl1-mesa libwayland-server0 libxcb-xfixes0
0 upgraded, 8 newly installed, 0 to remove and 174 not upgraded.
Need to get 2443 kB of archives.
After this operation, 8757 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us-central1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty/main libwayland-server0 amd64 1.4.0-1ubuntu1 [27.1 kB]
Get:2 http://us-central1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libgbm1 amd64 10.1.3-0ubuntu0.6 [19.0 kB]
Get:3 http://us-central1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty/main libxcb-xfixes0 amd64 1.10-2ubuntu1 [8486 B]
Get:4 http://us-central1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libegl1-mesa amd64 10.1.3-0ubuntu0.6 [59.1 kB]
Get:5 http://us-central1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libopenvg1-mesa amd64 10.1.3-0ubuntu0.6 [12.9 kB]
Get:6 http://us-central1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libwayland-egl1-mesa amd64 10.1.3-0ubuntu0.6 [6484 B]
Get:7 http://us-central1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libegl1-mesa-drivers amd64 10.1.3-0ubuntu0.6 [1993 kB]
Get:8 http://us-central1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/universe libsdl2-2.0-0 amd64 2.0.2+dfsg1-3ubuntu1.1 [317 kB]
Fetched 2443 kB in 0s (11.5 MB/s)       
Selecting previously unselected package libwayland-server0:amd64.
(Reading database ... 75752 files and directories currently installed.)
Preparing to unpack .../libwayland-server0_1.4.0-1ubuntu1_amd64.deb ...
Unpacking libwayland-server0:amd64 (1.4.0-1ubuntu1) ...
Selecting previously unselected package libgbm1:amd64.
Preparing to unpack .../libgbm1_10.1.3-0ubuntu0.6_amd64.deb ...
Unpacking libgbm1:amd64 (10.1.3-0ubuntu0.6) ...
Selecting previously unselected package libxcb-xfixes0:amd64.
Preparing to unpack .../libxcb-xfixes0_1.10-2ubuntu1_amd64.deb ...
Unpacking libxcb-xfixes0:amd64 (1.10-2ubuntu1) ...
Selecting previously unselected package libegl1-mesa:amd64.
Preparing to unpack .../libegl1-mesa_10.1.3-0ubuntu0.6_amd64.deb ...
Unpacking libegl1-mesa:amd64 (10.1.3-0ubuntu0.6) ...
Selecting previously unselected package libopenvg1-mesa:amd64.
Preparing to unpack .../libopenvg1-mesa_10.1.3-0ubuntu0.6_amd64.deb ...
Unpacking libopenvg1-mesa:amd64 (10.1.3-0ubuntu0.6) ...
Selecting previously unselected package libwayland-egl1-mesa:amd64.
Preparing to unpack .../libwayland-egl1-mesa_10.1.3-0ubuntu0.6_amd64.deb ...
Unpacking libwayland-egl1-mesa:amd64 (10.1.3-0ubuntu0.6) ...
Selecting previously unselected package libegl1-mesa-drivers:amd64.
Preparing to unpack .../libegl1-mesa-drivers_10.1.3-0ubuntu0.6_amd64.deb ...
Unpacking libegl1-mesa-drivers:amd64 (10.1.3-0ubuntu0.6) ...
Selecting previously unselected package libsdl2-2.0-0:amd64.
Preparing to unpack .../libsdl2-2.0-0_2.0.2+dfsg1-3ubuntu1.1_amd64.deb ...
Unpacking libsdl2-2.0-0:amd64 (2.0.2+dfsg1-3ubuntu1.1) ...
Setting up libwayland-server0:amd64 (1.4.0-1ubuntu1) ...
Setting up libgbm1:amd64 (10.1.3-0ubuntu0.6) ...
Setting up libxcb-xfixes0:amd64 (1.10-2ubuntu1) ...
Setting up libegl1-mesa:amd64 (10.1.3-0ubuntu0.6) ...
update-alternatives: using /usr/lib/x86_64-linux-gnu/mesa-egl/ld.so.conf to provide /etc/ld.so.conf.d/x86_64-linux-gnu_EGL.conf (x86_64-linux-gnu_egl_conf) in auto mode
Setting up libopenvg1-mesa:amd64 (10.1.3-0ubuntu0.6) ...
Setting up libwayland-egl1-mesa:amd64 (10.1.3-0ubuntu0.6) ...
Setting up libegl1-mesa-drivers:amd64 (10.1.3-0ubuntu0.6) ...
Setting up libsdl2-2.0-0:amd64 (2.0.2+dfsg1-3ubuntu1.1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...

greg06:~/workspace $ sudo apt-get install libsdl2-dev
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following package was automatically installed and is no longer required:
      gcc-4.8-base:i386
    Use 'apt-get autoremove' to remove it.
    The following extra packages will be installed:
      libasound2-dev libavahi-client-dev libavahi-common-dev libdbus-1-3
      libdbus-1-dev libdrm-amdgpu1 libdrm-dev libdrm2 libegl1-mesa-dev
      libgl1-mesa-dev libgles2-mesa libgles2-mesa-dev libglu1-mesa
      libglu1-mesa-dev libmirclient-dev libmirclient7 libmirclientplatform-mesa
      libmirprotobuf-dev libmirprotobuf0 libprotobuf-dev libprotobuf-lite8
      libprotobuf8 libpulse-dev libpulse-mainloop-glib0 libts-0.0-0 libts-dev
      libudev-dev libudev1 libwayland-dev libx11-xcb-dev libxcb-dri2-0-dev
      libxcb-dri3-dev libxcb-glx0-dev libxcb-present-dev libxcb-randr0
      libxcb-randr0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev
      libxcursor-dev libxdamage-dev libxfixes-dev libxi-dev libxinerama-dev
      libxkbcommon-dev libxrandr-dev libxshmfence-dev libxss-dev libxt-dev
      libxv-dev libxxf86vm-dev mesa-common-dev mircommon-dev tsconf udev
      x11proto-damage-dev x11proto-dri2-dev x11proto-fixes-dev x11proto-gl-dev
      x11proto-randr-dev x11proto-scrnsaver-dev x11proto-video-dev
      x11proto-xf86vidmode-dev x11proto-xinerama-dev
    Suggested packages:
      libasound2-doc libxt-doc
    The following NEW packages will be installed:
      libasound2-dev libavahi-client-dev libavahi-common-dev libdbus-1-dev
      libdrm-amdgpu1 libdrm-dev libegl1-mesa-dev libgl1-mesa-dev libgles2-mesa
      libgles2-mesa-dev libglu1-mesa libglu1-mesa-dev libmirclient-dev
      libmirclient7 libmirclientplatform-mesa libmirprotobuf-dev libmirprotobuf0
      libprotobuf-dev libprotobuf-lite8 libprotobuf8 libpulse-dev
      libpulse-mainloop-glib0 libsdl2-dev libts-0.0-0 libts-dev libudev-dev
      libwayland-dev libx11-xcb-dev libxcb-dri2-0-dev libxcb-dri3-dev
      libxcb-glx0-dev libxcb-present-dev libxcb-randr0 libxcb-randr0-dev
      libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxcursor-dev
      libxdamage-dev libxfixes-dev libxi-dev libxinerama-dev libxkbcommon-dev
      libxrandr-dev libxshmfence-dev libxss-dev libxt-dev libxv-dev libxxf86vm-dev
      mesa-common-dev mircommon-dev tsconf x11proto-damage-dev x11proto-dri2-dev
      x11proto-fixes-dev x11proto-gl-dev x11proto-randr-dev x11proto-scrnsaver-dev
      x11proto-video-dev x11proto-xf86vidmode-dev x11proto-xinerama-dev
    The following packages will be upgraded:
      libdbus-1-3 libdrm2 libudev1 udev
    4 upgraded, 61 newly installed, 0 to remove and 170 not upgraded.
    Need to get 5786 kB of archives.
    After this operation, 25.3 MB of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Abort.

#9

Please, someone could help me ?
I would like use the SDL library with cloud9 for a C program.


#10

Once you have successfully installed the library, you can include it in your C/C++ code like this:

#include <SDL.h>
#include <stdio.h>

// Your code here

I would suggest you take a look at the tutorials to learn how to use the library. This looks like a good starting point:

http://lazyfoo.net/tutorials/SDL/01_hello_SDL/linux/cli/index.php

Also remember that you can compile and run your code using the built-in runner in Cloud9.


#11

Thank again.

but it do not work.

    Running "/home/ubuntu/workspace/TestLibrary.c"
/home/ubuntu/workspace/TestLibrary.c:1:17: fatal error: SDL.h: No such file or directory
 #include <SDL.h>
                 ^
compilation terminated.

Process exited with code: 1

Your suggestion is good (use the tutorials), this is exactly what I would like to do, but until now impossible to install the SDL library.


#12

Hi,

If my understanding is correct, the library was uploaded but not on the good place.

SDL2 was install to /usr/include/SDL2


#13

I tried with #include <SDL2/SDL.h> and it work.

But I have a some new errors, test program :

        #include <stdlib.h>
        #include <stdio.h>
        #include <SDL2/SDL.h>
         
        int main(int argc, char *argv[])
        {
            SDL_Init(SDL_INIT_VIDEO);
     
   // Program
        SDL_Quit();
     
        return 0;
    }

Errors :
> Running “/home/ubuntu/workspace/TestLibrary.c”
> /tmp/ccTCrLrr.o: In function main': > TestLibrary.c:(.text+0x15): undefined reference toSDL_Init’
> TestLibrary.c:(.text+0x1a): undefined reference to `SDL_Quit’
> collect2: error: ld returned 1 exit status
> Process exited with code: 1