Segmentation Fault

Started by
6 comments, last by Funkymunky 15 years, 4 months ago
I just got an Asus EEE PC 2G surf. I decided to try a little SDL programming, so after learning about repositories and getting the -dev branch of the libsdl stuff, i wrote a barebones program which calls SDL_Init and SDL_Quit. It gives a "Segmentation Fault" error on SDL_Init(SDL_INIT_VIDEO). Everything else (except of course SDL_INIT_EVERYTHING) returns 0, but that has an error before it even returns. I'm brand new to this. Can anyone offer me any assistance?
Advertisement
anyone? I'm compiling it like this:

g++ -o MyProgram main.c -lSDL

but it still just gives a Segmentation Fault before it even returns from SDL_Init. Other programs, that I did not write, can succesfully use SDL. Can anyone point me in any kind of direction as to how to get started with this library?
Quote:Original post by Funkymunky
anyone? I'm compiling it like this:

g++ -o MyProgram main.c -lSDL

but it still just gives a Segmentation Fault before it even returns from SDL_Init. Other programs, that I did not write, can succesfully use SDL. Can anyone point me in any kind of direction as to how to get started with this library?


Try g++ -o MyProgram main.c `sdl-config --cflags --libs` (note: these are backticks, not single quotes). This is assuming the sdl-config script is in your path. If that doesn't help, please try posting the full source code, or a minimal example that displays this behaviour.

Also, while the compiler should definitely not care, ".c" extensions are typically used for C source code, not C++. C++ source code files often have one of the following extensions: .cc, .C (note: uppercase, often found on case sensitive file systems), .cxx, .cpp.
sure. i tried with your line, still the same behaviour.

#include <SDL/SDL.h>#include <stdio.h>int main(void){   int i;   printf("...\n");      i = SDL_Init(SDL_INIT_VIDEO);   printf("%i\n", i);   SDL_Quit();   return 0;}


no matter how i build it, results in this output:

Quote:...
Segmentation fault


(but again anything besides SDL_INIT_VIDEO and SDL_INIT_EVERYTHING returns 0 and works fine)

[Edited by - Funkymunky on December 29, 2008 11:49:39 PM]
This might sound strange, but try rebooting it. I've read a few SDL problems are solved with a reboot (e.g. this one, this one, etc).
thanks, but i've rebooted countless times

[Edited by - Funkymunky on December 30, 2008 12:56:40 AM]
Quote:Original post by Funkymunky
thanks, but i've rebooted countless times


Heh, I guessed that but it was worth a shot :-)

I would suggest running the program in a debugger to get a stack trace/more information. You could also try using strace to see what it's doing before the segfault, but a debugger would be the ultimate solution.
doh it's specifically related to the debian sdl package, i have to make a slight mod and build from source. thanks for trying to help me, please excuse me for being off base

This topic is closed to new replies.

Advertisement