Help - Search - Members - Calendar
Full Version: SDL not recognized by Gcc?
Linuxhelp > Support > Technical Support
spiroth10
I installed the latest SDL version from source, and everything built fine.
I then write a quick test app that just initiates SDL to see if all is running OK:
CODE
#include "SDL/SDL.h"
#include <stdio.h>

int sdlinit(){
    printf("Initialzing SDL\n");
    SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_TIMER );
    if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER)==-1)) {
    printf("Could not initialize SDL: %s.\n", SDL_GetError());
    }
    return 0;
}

int main(){
    sdlinit();
    printf("Everything is A-OK. Test over\n");
    SDL_Quit;    
    return 0;
}


I create my Makefile:
CODE
all: test

test: test.o
    gcc 'sdl-config --libs' test.o -o test

test.o: test.c
    gcc -c 'sdl-config --cflags' test.c


and in the end, I try to make it, and I get this:
CODE
gcc -c 'sdl-config --cflags' test.c
gcc: sdl-config --cflags: No such file or directory
test.c: In function `sdlinit':
test.c:6: error: `SDL_INIT_VIDEO' undeclared (first use in this function)
test.c:6: error: (Each undeclared identifier is reported only once
test.c:6: error: for each function it appears in.)
test.c:6: error: `SDL_INIT_TIMER' undeclared (first use in this function)
make: *** [test.o] Error 1


if I run sdl-config from console, it works fine. all libraries are in my PATH, and I ran ldconfig. I have absolutely no idea as to why it is not recognized by the compiler. I am grateful for any help, as I'd really like to get started developing some games.
Robert83
Hi,

Surround sdl-config --cflags with back-ticks .
It's an external app, so you need the shell to substitude its output in.
On line 8 you might want to fprintf() to stderr
And since this is C, line 13 should be int main(void) {
And, lines 6 and 7, there's no need to call SDL_Init twice.
(Just do it once, in your if condition.)
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER)==-1) { <- There was no need for those extra parentheses either.
Also, since sdlinit() takes zero arguments, you should also say int sdlinit(void) {

This was kindly provided by Tuxiscool . (so the credit is not mine smile.gif )

Sincerely
Robert B


ps.: this is what I've found out on IRC channel SDL on freenode.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.