• 11
• 9
• 10
• 9
• 11

Segmentation Fault

This topic is 3402 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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?

Share on other sites
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?

Share on other sites
Quote:
 Original post by Funkymunkyanyone? I'm compiling it like this:g++ -o MyProgram main.c -lSDLbut 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.

Share on other sites
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]

Share on other sites
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).

Share on other sites
thanks, but i've rebooted countless times

[Edited by - Funkymunky on December 30, 2008 12:56:40 AM]

Share on other sites
Quote:
 Original post by Funkymunkythanks, 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.