Recent

Author Topic: Settings for JEDI SDL  (Read 31806 times)

Ant_222

  • New Member
  • *
  • Posts: 24
Re: Settings for JEDI SDL
« Reply #15 on: January 22, 2009, 10:44:47 pm »
Yes, I can compile a Carbon app with Lazarus. But I don't know what mode the compiler should be in to compile the SDL app. I tried both Carbon and Cocoa, to no effect.

Libraries for the Lazarus version:
   @executable_path/../Frameworks/SDL.framework
   /System/Library/Frameworks/Cocoa.framework
   /usr/lib/libSystem.B.dylib


XCode version:

       @executable_path/../Frameworks/SDL.framework
   /System/Library/Frameworks/Cocoa.framework
   /usr/lib/libgcc_s.1.dylib
   /usr/lib/libSystem.B.dylib
   /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
   /usr/lib/libobjc.A.dylib
   /System/Library/Frameworks/CoreFoundation.framework
   /System/Library/Frameworks/AppKit.framework
   /System/Library/Frameworks/ApplicationServices.framework/Versions/A/
   /System/Library/Frameworks/Foundation.framework/Versions/C/


If I didn't see the GL library, it wouldn't compile or link, right? But it wouldn't successfully build a crashing program, would it?

Yes, I am using the Delphi mode because otherwise the the compiler just doesn't like the syntax of the sources.

Turning Run-time checks on revealed some problem in the Plasma demo (under the 2d directory) which occurred before initing the graphics. I commented that line and again got a crash at SetVideoMode.

EDIT:
Exactly the same problem is discussed here, and even an explanation of it is provided, but I don't get it:
http://www.gamedev.net/community/forums/topic.asp?topic_id=224420

« Last Edit: January 22, 2009, 10:52:54 pm by Ant_222 »

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Settings for JEDI SDL
« Reply #16 on: January 22, 2009, 10:52:55 pm »
Sounds like maybe you're not really creating an LCL app since the Cocoa widgetset is just a skeleton right now and not useable.

What about compiling with the NoGUI widgetset? That should exclude most of the LCL and widgetset code.

Thanks.

-Phil

Ant_222

  • New Member
  • *
  • Posts: 24
Re: Settings for JEDI SDL
« Reply #17 on: January 22, 2009, 10:54:57 pm »
The same old thing with NOGUI. Also see the EDIT in my previous post.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Settings for JEDI SDL
« Reply #18 on: January 22, 2009, 11:04:42 pm »
What do you see in Console.app when you run the app that crashes?

Again, I know nothing about SDL, but maybe you have to use XCode in order to properly initialize an SDL app.

-Phil

Ant_222

  • New Member
  • *
  • Posts: 24
Re: Settings for JEDI SDL
« Reply #19 on: January 22, 2009, 11:32:14 pm »
In console I see the same stuff as was mentioned at that forum.

Quote
Again, I know nothing about SDL, but maybe you have to use XCode in order to properly initialize an SDL app.

I have often read about FPC/Lazarus successfully used in conjunction with SDL. XCode uses the same compiler to produce a working app, so it must be possible with Lazarus as well.

I wish someone who have used SDL with FPC (and Lazarus) on the Mac would help me...

Anton


Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Settings for JEDI SDL
« Reply #20 on: January 24, 2009, 05:16:01 am »
Okay, this has nothing to do with Lazarus and everything to do with FPC - or rather, the FPC documentation and the current state of FPC and SDL.

I discovered that FPC already _includes_ the SDL units, so you don't need the JEDI 1.0RC2 .zip, which crashes, presumably because the SDM_main routine is not getting called.

The FPC sdl.pas is more recent than the 1.0RC2 sdl.pas. Look in:

/usr/local/share/fpcsrc/packages/sdl/src

In the older sdl.pas, we see this:

{$IFDEF DARWIN}
  SDLLibName = 'libSDL-1.2.0.dylib';

In the newer sdl.pas included with FPC, we see this:

{$IFDEF DARWIN}
  SDLLibName = 'libSDL-1.2.0.dylib';
  {$linklib libSDL-1.2.0}
  {$linklib SDLmain}
  {$linkframework Cocoa}
  {$PASCALMAINNAME SDL_main}

Those extra lines is a good sign that something is up. In neither case are we linking with the indicated library - instead, we're using the SDL.framework. I believe the SDLLibName is ignored since it's only used in the external part of the function declarations. And the first $linklib can be taken out.

However, the 2nd $linklib points to a non-existent file, at least I can't find it on my system. This is where the SDL_main routine is and I suspect this is needed to properly initialize things.

Using otool -Tv SDL on the library inside the SDL.framework we see that it doesn't export any routine with that name. So where is this function?

Good question. The wiki documentation was clearly written without the SDL.framework in mind and needs to be updated.

Here's a related thread from May 5:

http://www.hu.freepascal.org/lists/fpc-devel/2008-May/013675.html

Note that FPC's sdl.pas is stamped May 31. I suspect that Jonas updated sdl.pas for FPC but didn't update any documentation. And without a working example (examples and tests are both empty in packages/sdl) I don't know how to go beyond this, but certainly we're now in the ballpark.

Welcome to open source if you haven't run into this sort of confusion before.

Thanks.

-Phil

Ant_222

  • New Member
  • *
  • Posts: 24
Re: Settings for JEDI SDL
« Reply #21 on: January 24, 2009, 12:37:25 pm »
Hello Phil!

Many thanks for the info. I am not at home right now, so I'll try it a bit later. The only problem is that I don't know how to pass options to FPC through Lazarus. Compiling from the command line is not comfortable because the command with all the options for unit inclusion takes a lot of space...

Can I set the -XMSDL_main option in FPC.cfg?

Many many thanks,
Anton

EDIT: as for the lacking SDLmain lib, I compiled it on my Mac from sources provided in the framework and added to the lib path in Lazarus.
« Last Edit: January 24, 2009, 12:38:59 pm by Ant_222 »

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Settings for JEDI SDL
« Reply #22 on: January 24, 2009, 01:25:10 pm »
You can pass options to the FPC in the compiler options. If there is no gui control for this specific option, you can type your option in Compiler Options -> Other -> Custom options.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Settings for JEDI SDL
« Reply #23 on: January 24, 2009, 05:20:02 pm »
Okay, it works. Here's what I did:

(1) Compiled SDLmain.o from SDLmain.m:

gcc -c -I/Library/Frameworks/SDL.framework/Headers SDLmain.m

(used the "nibless" SDLmain.m)

(2) Copied SDLmain.o to jedi-sdlv1.0/sdl/pas folder.

(3) Created testsdl.pas in same folder to simplify compiling:

program testsdl;

{$linklib gcc}
{$linklib SDLmain.o}
{$linkframework Cocoa}
{$PASCALMAINNAME SDL_main}

uses sdl;

var
  scr : PSDL_Surface;
begin
  SDL_Init(SDL_INIT_VIDEO);
  scr := SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
  SDL_Quit;
end.

(4) Compiled test app:

fpc -Sd -k"-framework SDL" testsdl.pas

Notes:
- Took a cue from FPC's sdl.pas and specified the app's "main" routine so don't have to use -XM switch.
- For cross-platform work, you can put the 4 compiler directives in this:
  {$IFDEF DARWIN}
  {$ENDIF}
- Note no use of XCode is required.
- Documentation in Lazarus wiki needs to be updated to account for (i) SDL.framework use and how/where to install, (ii) how to create SDLmain.o object file, (iii) clarification for those completely unfamiliar to SDL, (iv) maybe better example, (v) whether/how to use FPC's SDL units. Can you do this? You don't need any special privileges to edit the wiki.

Thanks.

-Phil

Ant_222

  • New Member
  • *
  • Posts: 24
Re: Settings for JEDI SDL
« Reply #24 on: January 24, 2009, 09:22:45 pm »
Many thanks!

I had been in a pinch off the solution myself. All I had to do was:
1. Include {$linklib SDLmain}
2. Use the MXSDL_main option

I had tried each of them separately, but not together.

Thank you so much for the help, Phil and Vincent :)))

My working program works like this:
program sdltest;

{$linklib SDLmain}

uses sdl;

var scr: PSDL_Surface; // Our main screen
  var err:integer;
    rect: TSDL_Rect;

begin
  err := SDL_Init(SDL_INIT_VIDEO); // Initialize the video SDL subsystem
  if err = 0 then begin
    scr:=SDL_SetVideoMode(640, 480, 0, SDL_SWSURFACE); // Create a software window of 640x480x8 and assign to scr
    with rect do begin
      h := 10; w := 10; x:= 50; y := 50;
    end;
    SDL.SDL_FillRect(scr,@rect,SDL.SDL_MapRGB(scr^.format,255,255,255));
    SDL.SDL_Flip(scr);
    SDL.SDL_Delay(10000);
    SDL_Quit; // close the subsystems and SDL
  end;
end. 


Compiler options include -MXSDL_main and linker options -framework sdl. The program is compiled against the Cocoa widget set.

Anton
« Last Edit: January 24, 2009, 09:26:51 pm by Ant_222 »

cybermonkey342

  • New Member
  • *
  • Posts: 42
    • Home of EGSL interpreter
Re: Settings for JEDI SDL
« Reply #25 on: June 13, 2009, 06:29:02 pm »
Sorry for posting in this old topic but I still have my problems with FPC and SDL.  :(
I tested with gcc and it works fine. I compiled the program SDL_Basic on http://www.linuxmotors.com/SDL_basic/ so I thought I should try my luck with FPC again.
This is what I wanted to do: compile the game Oxygene from the JEDI-SDL examples.

(1) Compiled SDLmain.o from SDLmain.m:

gcc -c -I/Library/Frameworks/SDL.framework/Headers SDLmain.m

(2) Copied SDLmain.o to Oxygene folder (could there be the problem, but to WHERE shall I copy SDLmain.o because I am NOT using the JEDI libraries but the one shipped with fpc 2.2.4)

This I added to the Oxygene source:
Quote
{$linklib gcc}
{$linklib SDLmain.o}
{$linkframework Cocoa}
{$PASCALMAINNAME SDL_main}
(4) Compiled test app:

fpc -Sd -k"-framework SDL" -XMSDL_main Oxygene.dpr

And the result:
Quote

Free Pascal Compiler version 2.2.4 [2009/04/05] for i386
Copyright (c) 1993-2008 by Florian Klaempfl
Target OS: Darwin for i386
Compiling Oxygene.dpr
Warning: Overriding name of "main" procedure multiple times, was previously set to "SDL_main"
Compiling ../../Pas/sdlsprites.pas
Assembling sdlsprites
Oxygene.dpr(1977,15) Warning: Local variable "f" does not seem to be initialized
Oxygene.dpr(316,3) Note: Local variable "FullScreen" is assigned but never used
Assembling oxygene
Linking Oxygene
ld: library not found for -lSDL-1.2.0
An error occurred while linking
Error: Error while linking
Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)
Again: SDL IS installed correctly because I can compile C/C++ programs from the bash, so why doesn't FPC find it?

EDIT: OS is MAC OS X 10.5.2

EDIT: I also tried as described in the wiki giving the path to the (newly) compiled libSDLMain.a library.
« Last Edit: June 14, 2009, 05:15:42 pm by cybermonkey342 »
--
Best regards

cybermonkey342

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Settings for JEDI SDL
« Reply #26 on: June 15, 2009, 07:18:23 am »
I haven't checked SDL units distributed with FPC, but it could be that the library name is SDL-1.2.0 so the linker will accept -lSDL-1.2.0 while AFAIK the main SDL library is SDLmain. If you can compile it under gcc, you can rename the library name in SDL source to the one passed to gcc linker.

 

TinyPortal © 2005-2018