Author Topic: how to put my header of SDL  (Read 533 times)

Offline philo_neo

  • Multiple posting newcomer
  • *
  • Posts: 19
how to put my header of SDL
« on: May 24, 2018, 01:50:36 am »
Hello,
I develop in C language a graphics applications with SDL and SDL2.
my system is Fedora 28 server x86_64.
my problem is that I do not arrive in settings >> globals variables...
Address the header of the SDL (.h), so the addition of the directive <SDL.h> is in error.
the installation of the SDL is in the following directory: /usr/include/SDL or  /usr/include/SDL2

Question, how to put my header in Code:: blocks?

Regards
Philippe
« Last Edit: May 24, 2018, 10:40:40 pm by philo_neo »

Offline headkase

  • Almost regular
  • **
  • Posts: 158
Re: how to put my header of SDL
« Reply #1 on: May 24, 2018, 02:05:38 am »
I'm not entirely sure but I think you need to include:

#include <SDL2/SDL.h>

Instead of

#include <SDL.h>

This is a vague impression though, I think the change to preface with "SDL2/" was made because of compatibility with SDL 1.

Offline philo_neo

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: how to put my header of SDL
« Reply #2 on: May 24, 2018, 02:33:17 am »
yes but my main problem is that in the menu >> Settings >> global variables...
Code:: bloks can not find the directory path of the SDL or SDL2,
How to declare my header (all *.h) in code:: blocks 17.12.

Offline headkase

  • Almost regular
  • **
  • Posts: 158
Re: how to put my header of SDL
« Reply #3 on: May 24, 2018, 03:25:52 am »
It's sounding like you need to set up your include and libs folders.  See these instructions for doing it with SFML:

https://www.sfml-dev.org/tutorials/2.5/start-cb.php

Do the same thing but with the SDL2 folder paths instead.

Just set up the include and lib folders, everything else is specific to SFML and not SDL2.

Offline philo_neo

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: how to put my header of SDL
« Reply #4 on: May 24, 2018, 04:16:25 am »
with this code

Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <SDL2/SDL.h>

int main(int argc, char *argv[])

{

    SDL_Init(SDL_INIT_VIDEO); // Démarrage de la SDL (ici : chargement du système vidéo)
    /*

    La SDL are loaded.
    program loaded, write your code here !!!

    */
    SDL_Quit(); // Arrêt de la SDL (libération de la mémoire).



    return 0;

}

this is my output of built log !

Quote
-------------- Build: Debug in test_sdl2_101 (compile: GNU GCC Compiler) ---------------

gcc -Wall -g -I ../../../../../ usr / include / SDL -c /home/phipo/c/perso/essai_sdl2_101/main.c -o obj / Debug / main .o
g ++ -L / usr / include / SDL -L / usr / include / SDL2 -o bin / Debug / test_sdl2_101 obj / Debug / main.o
obj / Debug / main.o: In the "main" function:
/home/phipo/c/perso/essai_sdl2_101/main.c:11: Indefinite reference to "SDL_Init"
/home/phipo/c/perso/essai_sdl2_101/main.c:25: Indefinite reference to "SDL_Quit"
collect2: error: ld returned output status 1
Process terminated with status 1 (0 minute (s), 0 second (s))
1 error (s), 0 warning (s) (0 minute (s), 0 second (s))

Should you make a program with an initialization of the SDL?

Offline philo_neo

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: how to put my header of SDL
« Reply #5 on: May 24, 2018, 05:25:19 am »
with this program I should get the window as an attachment

Code: [Select]
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <SDL2/SDL.h>

void pause();



int main(int argc, char *argv[])

{
    SDL_Init(SDL_INIT_VIDEO); // Initialisation de la SDL
    SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE); // Ouverture de la fenêtre
    pause(); // Mise en pause du programme
    SDL_Quit(); // Arrêt de la SDL
    return EXIT_SUCCESS; // Fermeture du programme
}

void pause()
{
    int continuer = 1;
    SDL_Event event;
    while (continuer)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
            case SDL_QUIT:
                continuer = 0;
        }
    }
}
rhe swall image !!



Offline sodev

  • Almost regular
  • **
  • Posts: 166
Re: how to put my header of SDL
« Reply #6 on: May 24, 2018, 10:03:33 am »
You don't have a compilation problem, you have a linking problem. Your headers are found fine, the problem is that you don't link to any SDL library. You have to add the required libraries to the link libraries.

Offline philo_neo

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: how to put my header of SDL
« Reply #7 on: May 24, 2018, 10:40:02 pm »
Then password (You can remove SDL_image and SDL_ttf if you do not need it, but if you follow m @ teo tutorial, you will need it at one time or another).

Then, in codeblocks, it is enough to make new SDL project, and normally it compiles alone (on the other hand, withdraws the main.cpp of the project, replaces it by main.c, saves in user-template to avoid having to do again the manipulation each time: you can call it SDL C). By default code :: blocks uses C ++ with SDL, and not C, the user template avoids this.



Post // thread SOLVED