PDA

View Full Version : MacOS X + JEDI SDL + Fink



billy1380
18-10-2006, 08:50 PM
I am using Lazarus under OS X (X11) to compile a game developed under (win32/linux).

So far I have managed to get it all to compile (after clipping some bits out)! I am having major problems with the linker though... it seems to throw an error about not finding symbols like _SDL_Init etc. pretty much all of the ones defined in SDL.pas.

I have tried downloading the SDL libraries from http://www.libsdl.org/download-1.2.php but they seem to be in framework form!!?? So I tried to use fink instead and to get libSdl.dylib... but still it does not seem to solve the problem, even when I add the path /sw/lib to the compiler settings...

Would anyone care to shed any light on this situation? I am going about this completely the wrong way?

WILL
18-10-2006, 09:41 PM
Welcome to PGD! :)

Hmm... well I don't have any instant 'ah ha's here, but there are some small bits of information missing that I think would clue in others wanting to help you out.

Whats the SDL library you are using? (Are they JEDI-SDL?) (EDIT: nm, I didn't notice the Subject too well. :P)

What version of Laz?

What calls are you making?, etc

billy1380
18-10-2006, 10:30 PM
Ok...
First things first, thanks for the prompt response...

Now,

Here is some more information... Hmmm...

I am porting a game called Guns for a friend (also a member of PGD - jasonf)... using lazarus version 0.9.18 beta...

On the SDL side of things - I am using:
SDL (through JEDI-SDLv1.0b)
SDL-Image (through JEDI-SDLv1.0b)
SDL-mixer (through JEDI-SDLv1.0b)
- also - SFont (through JEDI-SDLv1.0b)

He is makeing all sorts of calls in there... loading graphics, music etc...

I hope you have seen the game because I am pretty sure this post does not qualify as more information... the truth is that my knowledge of the code base is quite ***t :oops:.

technomage
19-10-2006, 09:40 AM
Good luck on the port billly1380 :)

I know Jason and I have seen the code you are converting (I think I even worked on some of it :D ). For the most part it should work under lazarus, just make sure you are using the {$MODE DELPHI} or the Delphi compatable option in your project as the code was written using kylix and delphi 5.

There was some postson the JEDI-SDL group about compiling under mac OSX and you have to link the dynlib into the main applications, I'll try and find the post about it and put it up here.



Dean

billy1380
19-10-2006, 06:02 PM
Hey technomage - thanks for the support...

About the Delphi thing... I think that one of the compiler options in the version of Lazarus I am using passes that option to the compiler... It would not talk to me without that option switched on :cry:.

I could really use that article actually... if you can get your hands on it, I woud be very grateful, as I had a look and have come up with nothing.

Thanks again...

savage
19-10-2006, 11:04 PM
I intend to ask for an abandoned iMac in my office. Does anyone know if iMacs will run MacOS X and or FPC?

billy1380
20-10-2006, 11:06 AM
I an not sure which iMacs you are talking about but the ones with the extendible screen mount thing were launched when MAC OS X was Jaguar so 10.2. They are mostly G3s but there are some out there that are G4... So yes they run OS X...

So much has changed since the days of Jaguar though and if you get that bad boy, I would seriously recomend a software upgrade (subject to the specs :wink: ).

billy1380
20-10-2006, 10:40 PM
Can anyone with access to a mac post up a realy simple JEDI-SDL project compiled with Lazarus. Something that you know compiles and runs under Mac OS X e.g. a roatating cube or something.

Might be useful to look a the settings on that... see if it links on my machine...

technomage
20-10-2006, 10:49 PM
I found the link for getting sdl and fpc working under macos

http://www.freepascal.org/wiki/index.php/FPC_and_SDL

billy1380
21-10-2006, 01:55 AM
Thanks... for the help...

I read that article and managed to get it to link...

Turns out that sticking the library path into the compiler settings is not enough, you need to tell the linker what you want it to link to e.g. -k-lSDL...

Next: getting it to run! :lol:

savage
21-10-2006, 02:25 PM
I found the ]http://www.freepascal.org/wiki/index.php/FPC_and_SDL[/url]

What a great little tutorial. I especially like the tips about getting JEDI-SDL working on MacOS X.

I've added another tip to that Wiki page. It being that when using SDL_mixer, the call to Mix_OpenAudio MUST happen before the call to SDL_SetVideoMode, otherwise you will get a ( sometimes load ) audible pop.

savage
21-10-2006, 03:04 PM
[quote="billly1380"]
Turns out that sticking the library path into the compiler settings is not enough, you need to tell the ]

The wiki page does mention that you need to add that to the command line.

Btw, did it all work?
How much do you charge to recompile and create a binary under MacOS X :)?
Also, are you using it under Intel or Power PC?

jasonf
21-10-2006, 03:32 PM
Hehehe.. Will, looks like you could have yourself a cushy side earner here ;)

So did you get Guns to compile and run on the Mac? I'd love to see it working.. also, I've got some major updates for you to include.

WILL
21-10-2006, 09:25 PM
Oh man... this thread makes me wish C-C was ready for such porting. :P

Nice job guys! ;)

savage
21-10-2006, 09:47 PM
C-C??

billy1380
21-10-2006, 10:49 PM
The wiki page does mention that you need to add that to the command line.

Btw, did it all work?
How much do you charge to recompile and create a binary under MacOS X :)?
Also, are you using it under Intel or Power PC?

Since I am using Lazarus I could not play with the command line directly so I had to add all the -k swithches to the additional ]
I've got some major updates for you to include.
[/quote]

bring on the updates... :wink:

Although I think we need to sort out that display issue first! :lol:

WILL
21-10-2006, 10:57 PM
C-C??

:lol: My short acronym for Cyber-Crisis! :D

savage
21-10-2006, 11:24 PM
The funny thing (actually not so much) is that it crashes with a bad pointer doing an SDL_Flip... /quote]

Which version of the FPC compiler are you using? My hunch is that the SDL_Main.o is what is causing the problem. But I could be totally wrong. According to that wiki if you are using FPC v2.0.0...
[quote]
The only workaround currently is to edit rtl/bsd/system.pp, and change the line

procedure main(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];

into

procedure SDL_main(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];

If you then recompile the RTL, you will obtain an RTL which can be used to compile SDL programs. However, it will only work for SDL programs, since other programs now won't have a main function.


If you are using FPC v2.0.2+...


With fpc 2.0.2 or later you do not have to change rtl/bsd/system.pp any longer. -XMSDL_main does the trick :
1) as before, install SDL, for example using fink.

2) Add the following to your program:

{$linklib gcc}
{$linklib SDLmain}
uses sdl;

3) Then, this command line does it:

fpc -XMSDL_main -k-L/sw/lib -k-lSDL -k-framework -kOpenGL -k-framework -kCocoa -Fu<pathtosdl.pas files> -Fi<pathtosdl.inc files> Guns.dpr


If neither of these 2 methods work then we need to inform the wiki guys to update their info.

billy1380
22-10-2006, 01:21 PM
If neither of these 2 methods work then we need to inform the wiki guys to update their info.

I am using fpc 2.0.4 and the method I used (2.0.2+) was as described in the Wiki... the only thing is that I could not get hold of a version of SDL_Main.o (for ppc)... so I had to build one myself!

I think the SDLMain bit works because I get a cocoa window (part of their main code) it just has nothing in it...

The runtime error I am getting is 'External: EXC_BAD_ACCESS'
error detail 'KERN_PROTECTION_FAILURE'.
I read this thread...

http://forums.macosxhints.com/archive/index.php/t-3539.html

I think I am still in denial :!: !

savage
22-10-2006, 02:05 PM
Hmm I'm very keen to see Guns blazing on MacOS X.
I know you are currently using Lazarus, but would you mind trying to compile the game via the command line, to see if that works instead? Trying both with your SDL_Main and the one that the wiki says is supposed to be there.
My understanding of the -XMSDL_Main command line switch is that it should rename the system.pp main() to SDL_Main() during compilation to facilitate SDL compilation, hence my surprise that you had to create your own.

Personally the last time I used Lazarus under Unix I had problems getting some of the JEDI-SDL demos working, so in the end I switched to using the command line compiler. I cannot deny that it may not have worked because of my lack of familiarity with Laz, but at the time it seemed quicker to just get things working using the command line compiler.

billy1380
22-10-2006, 04:09 PM
Ok, now I get what you are saying...

I will try that and report shortly...

Thanks :D

billy1380
22-10-2006, 04:19 PM
so here is the command line (I renamed my SDLmain.o out of the way for this test):

/usr/local/bin/fpc -XMSDL_main -k-L/sw/lib -k-lSDL -k-lSDL_image -k-lSDL_Mixer -k-framework -kOpenGL -k-framework -kCocoa -Fu/users/billy1380/Documents/XCodeProjects/CBC/Jedi-SDLv1.0/SDL/pas -Fu/users/billy1380/Documents/XCodeProjects/CBC/Jedi-SDLv1.0/SDL_Image/pas -Fu/users/billy1380/Documents/XCodeProjects/CBC/Jedi-SDLv1.0/SDL_Mixer/pas -Fu/users/billy1380/Documents/XCodeProjects/CBC/CBCFoundation -Fu/users/billy1380/Documents/XCodeProjects/CBC/Jedi-SDLv1.0/sfont/pas -Fi/users/billy1380/Documents/XCodeProjects/CBC/Jedi-SDLv1.0/SDL/pas -Fi/swab/include/SDL SDLGuns.pas -Fl/sw/lib -Fl/usr/X11R6/lib

and the result is:


Copyright &#40;c&#41; 1993-2006 by Florian Klaempfl
Target OS&#58; Darwin for PowerPC
Compiling SDLGuns.pas
Assembling sdlguns
SDLGuns.pas&#40;52,1&#41; Warning&#58; Object SDLmain.o not found, Linking may fail !
Linking SDLGuns
/usr/bin/ld&#58; can't open&#58; SDLmain.o &#40;No such file or directory, errno = 2&#41;
SDLGuns.pas&#40;52,1&#41; Error&#58; Error while linking
Error&#58; /usr/local/bin/ppcppc returned an error exitcode &#40;normal if you did not specify a source file to be compiled&#41;

sorry about all the extra long paths...

savage
22-10-2006, 05:47 PM
Damn!! Maybe the MacOS X 2.0.4 compiler doesn't have the SDL_Main fix.

OK last suggestion, find system.pp, inside that file find main(...) and rename it to SDL_Main. Then you would need to recompile the RTL and I'm not sure how to do that. If you manage to compile the RTL, you can then try the command line compile again but this time don't use the -XMSDL_main switch as it should not be needed now.

If I find an explanation of how to recompile the RTL I'll post it here.

savage
22-10-2006, 05:55 PM
I found this...
http://community.freepascal.org:10000/bboards/message?message_id=218152&forum_id=24084

which states something like ( paraphrased )..


After installing mingW 3.1, try to compile it so:

make rtl DEBUG=1
make compiler DEBUG=1
make ide DEBUG=1

make -C fv DEBUG=1
make installer DEBUG=1


Not sure if it is accurate.

billy1380
26-10-2006, 09:13 AM
Finally, yesterday night, we got guns to run "properly" on the Mac... :D

and so I would like to thank all of you who posted to help and/or support...

And just incase the big guy really does exist... I would like to thank Santa...

So here is a screenshot for all you screenshot lovers:

http://upload4.postimage.org/1491201/gunsmac.jpg (http://upload4.postimage.org/1491201/photo_hosting.html)

:wink:

savage
26-10-2006, 12:22 PM
Congratulations guys!

So Billy, can you pass on any information about how you finally got everything working on MacOS X? I will happily update the FreePascal wiki with any information you provide, so that others don't have to go through the same night mare.

savage
04-11-2006, 06:21 PM
Hi Guys,
Can you post exactly what command line you used on MacOS X to get everything to compile. I am using

/usr/local/bin/fpc -XMSDL_main -k-L/Library/Frameworks -k-lSDL -k-framework -kOpenGL -k-framework -kCocoa SDLDemo.pas


but keep getting

/usr/bin/ld: can't locate file for: -lSDL

I'm using FPC 2.1.1. any ideas?

billy1380
06-11-2006, 03:50 PM
There is nothing wrong with your command line... I will post the entire thing when I get home!

For the time being I think that the problem is that you do not actually have the SDL framework... to get that just go to libSDL.org and get the latest version... you will find that it is a dmg... copy the contents (SDL.framework folder) into your /library/frameworks directory...

try again...

savage
06-11-2006, 04:52 PM
The SDL.framework is definately there ( in the location you mentioned ) along with SDL_image etc. From chatting to Jonas ( the MacOS X maintainer ), I need to link to libSDLMain.a to get things going. Just to make things interesting I am also trying to get it working with XCode 2.4.

billy1380
06-11-2006, 05:31 PM
so here is the command line unedited:



/usr/local/bin/fpc -Or -XMSDL_main -k-L/sw/lib -k-lSDL -k-lSDL_image -k-lSDL_Mixer -k-framework -kOpenGL -k-framework -kCocoa -Fu/users/~/Documents/XCodeProjects/CBC/Jedi-SDLv1.0/SDL/pas -Fu/users/~/Documents/XCodeProjects/CBC/Jedi-SDLv1.0/SDL_Image/pas -Fu/users/~/Documents/XCodeProjects/CBC/Jedi-SDLv1.0/SDL_Mixer/pas -Fu/users/~/Documents/XCodeProjects/CBC/CBCFoundation -Fu/users/~/Documents/XCodeProjects/CBC/Jedi-SDLv1.0/sfont/pas -Fi/users/~/Documents/XCodeProjects/Jedi-SDLv1.0/SDL/pas -Fi/sw/include/SDL SDLGuns.pas -Fl/sw/lib -Fl/usr/X11R6/lib

notice the use of -k-L/sw/lib, this is where libSDL.dylib is located!

jasonf
06-11-2006, 05:32 PM
Just out of curiosity, has anyone heard of the forum iDev Games before? They seem to specialise in Mac game development and they've got a section on SDL. They might have some useful info.. http://www.idevgames.com/forum/forumdisplay.php?f=6

savage
06-11-2006, 06:59 PM
Looks promising, you should announce your port over there.

billy1380
12-11-2006, 05:19 PM
Hey,

I promised to put an article together for any of you who are interested in porting their games to the Mac!

So here is the link:
http://www.cerebral-bicycle.co.uk/viewdoc.asp?doc=349

Hope you find it useful, and as always... if you would like some help or have any questions just post them up!

jasonf
13-11-2006, 02:04 AM
In my completely non biased opinion ;) this should be an announcement or at least have a link of its own :D

Top cheers to Billy for taking the time and effort to get my shoddy (tm) code to work on his mac.. pleased to announce that since my optimisations, it's working as fast as a fast thing.
I'm sure that there are people who would like to get their Jedi-sdl apps running on Mac and will find your tutorial no end of help. A few simple guidelines can make all the difference.

Cheers Billy mate.

savage
13-11-2006, 07:08 PM
Thank Billy for posting the info about building under MacOS X. Though I love the references to delphigamer.com :), I think it would be more consistent to change this to http://www.pascalgamedevelopment.com/ as Dean has indicated that DelphiGamer may change in future.

I will create a news item about your post and I will also be creating a tutorial about how to use XCode 2.4.x with FPC and JEDI-SDL, incase some developers don't want to use Lazarus on MacOS X.

billy1380
14-11-2006, 08:51 PM
I think it would be more consistent to change this to http://www.pascalgamedevelopment.com/ as Dean has indicated that DelphiGamer may change in future.

Done...

I am actually really looking forward to your article as I had to give up on the XCode plugin...

savage
14-11-2006, 10:22 PM
Done...


Thanks.



I am actually really looking forward to your article as I had to give up on the XCode plugin...

I have a 2D JEDI-SDL Project template which is 99% done. If I could just get the project renaming done it would be ready. I'm hoping that Jonas can point me in the right direction on that one.

savage
18-11-2006, 06:06 PM
OK the 2D Project template now works and I have posted my basic XCode instructions in this - http://www.pascalgamedevelopment.com/viewtopic.php?p=27487 thread.
All feedback or corrections welcome.

savage
27-11-2006, 12:40 PM
A MacOS X Disk Image is now available from
http://jedi-sdl.pascalgamedevelopment.com/files/JEDI-SDL.dmg, which contains both the JEDI-SDL framework and the 2D and 3D project templates. The only thing left to add to these are the ability to make them double clickable from within *Finder* so that they can be executed like normal MacOS X exes. Currently they behave more like UNIX exes.

czar
02-12-2008, 08:48 AM
Hi Savage, where did the dmg go?

Was it no longer useful?

czar
05-12-2008, 08:11 PM
Savage?

savage
06-12-2008, 03:08 PM
I stopped supporting it as I never got any feedback, but I would need to sit down one week-end and create another more updated dmg. Realistically you don't need it if you plan to use JEDI-SDL. Also keep in mind that FPC/Lazarus ships with some JEDI-SDL headers.

czar
07-12-2008, 01:15 AM
Ok,

I have installed sdl but I can't seem to get the examples to compile - can you tell me if the examples are supposed to run with mac os? If so I will have another crack at it.