Page 1 of 1

Freepascal error with SDL

Posted: Fri Mar 21, 2014 10:04 am
by Edy81
How can I compile this ?

program sdltest;
{$linklib gcc}
{$linklib SDLmain}
uses sdl;
var
scr: PSDL_Surface; // Our main screen
begin
SDL_Init(SDL_INIT_VIDEO); // Initialize the video SDL subsystem
scr:=SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); // Create a software window of 640x480x8 and assign to scr
SDL_Quit; // close the subsystems and SDL
end.

yes is the demo at the wiki of lazarus

they say use

fpc -Fu<pathtosdl.pas files> -Fi<pathtosdl.inc files> example.pas

but I don't know where are the inc files and the error is something can't find
lgcc

My FPC install is without lazarus I plan to use raspberry just with keyboard so I'm just on a terminal no x11

Re: Freepascal error with SDL

Posted: Fri Mar 21, 2014 7:51 pm
by Thaddy
First, you have to check where libggc.a is installed.
You can find it by typing;
sudo / -name libgcc.a

It is probably in /usr/lib.
In that case type:
export GCCLIBDIR=/usr/lib

Now fpc will be able to find GCC.
Let me know what the next error is.
Otherwise install FPC2.7.1 from http://freepascal.thaddy.co.uk/raspberrypi.html
and try again.
The versions on my website are almost never more than a few days old and may help.

Re: Freepascal error with SDL

Posted: Thu Mar 17, 2016 3:21 pm
by mob-i-l
I can compile and run the example if i remove the line with gcc. I discovered it's possible to also remove the line with SDLmain. I added a 5 s delay so I can see the window.

Code: Select all

program sdltest;
uses sdl;
var 
  scr: PSDL_Surface; // Our main screen
begin
  SDL_Init(SDL_INIT_VIDEO); // Initialize the video SDL subsystem
  scr:=SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); // Create a software window of 640x480x8 and assign to scr
  SDL_Delay(5000);
  SDL_Quit; // close the subsystems and SDL
end.
I installed fpc using sudo apt-get install lazarus-ide-gtk2 (I had to fix some things manually after installation to get Lazarus IDE to work with code completion -- YMMV). I first installed the SDL-libraries following http://pp4s.co.uk/main/gs-pi-sdl.html. I have downloaded SDL-headers in the directory above my project using git clone https://github.com/ev1313/Pascal-SDL-1.2-Headers.git. I compile with:
fpc -Fu../Pascal-SDL-1.2-Headers/ -Fi../Pascal-SDL-1.2-Headers/ sdltest.pas and run with ./sdltest. This example works both with and without X-Windows. The other SDL-examples on PP4S also worked.