Settings for JEDI SDL lazarus / 11-Options ---------------------------------------------------------------------- Ant_222 · 2009-01-21 01:19 Hello all, I tried making Lazarus work with JEDI SDL on Mac OS X and ran into the following problem. When building I get the "Error while linking" message. Could you help me? Anton ---------------------------------------------------------------------- Phil · 2009-01-21 02:21 How about some more information? Version of Lazarus and Free Pascal, version of OS X, version of SDL, etc. Also, please give the full linker error message. Thanks. -Phil ---------------------------------------------------------------------- Ant_222 · 2009-01-21 12:35 Hello, Phil Mac OS X version: 10.5.6 Lazarus version: 0.9.26 FPC version:2.2.2 SDL version: 1.2.13 JEDI-SDL version 1.0 Final RC2 As for the linker error, that's all it writes in Lazarus. I suppose I have to add a certain option to the linking command so that it would log the detailed error description in a file? Anton ---------------------------------------------------------------------- Vincent Snijders · 2009-01-21 12:53 Try to copy all including hidden messages form the messages view. ---------------------------------------------------------------------- Ant_222 · 2009-01-21 12:59 Thanks for the tip. Here it is: Assembling sdl Project1.pas(9,5) Note: Local variable "scr" not used Assembling sdltest Linking Project1 Undefined symbols:   "_SDL_Init", referenced from:       _PASCALMAIN in Project1.o ld: symbol(s) not found An error occurred while linking Error: Error while linking That was with smart linking turned on. Without it I get a whole bunch undefined symbols: Linking Project1 Undefined symbols:   "_SDL_LoadWAV_RW", referenced from:       _SDL_SDL_LOADWAV$PCHAR$PSDL_AUDIOSPEC$PUINT8$PUINT32$$PSDL_AUDIOSPEC in sdl.o   "_SDL_RWFromFile", referenced from:       _SDL_SDL_LOADWAV$PCHAR$PSDL_AUDIOSPEC$PUINT8$PUINT32$$PSDL_AUDIOSPEC in sdl.o       _SDL_SDL_LOADBMP$PCHAR$$PSDL_SURFACE in sdl.o       _SDL_SDL_SAVEBMP$PSDL_SURFACE$PCHAR$$LONGINT in sdl.o   "_SDL_Error", referenced from:       _SDL_SDL_OUTOFMEMORY in sdl.o   "_SDL_UpperBlit", referenced from:       _SDL_SDL_BLITSURFACE$PSDL_SURFACE$PSDL_RECT$PSDL_SURFACE$PSDL_RE CT$$LONGINT in sdl.o   "_SDL_Init", referenced from:       _PASCALMAIN in Project1.o   "_SDL_SaveBMP_RW", referenced from:       _SDL_SDL_SAVEBMP$PSDL_SURFACE$PCHAR$$LONGINT in sdl.o   "_SDL_LoadBMP_RW", referenced from:       _SDL_SDL_LOADBMP$PCHAR$$PSDL_SURFACE in sdl.o   "_SDL_mutexP", referenced from:       _SDL_SDL_LOCKMUTEX$PSDL_MUTEX$$LONGINT in sdl.o   "_SDL_mutexV", referenced from:       _SDL_SDL_UNLOCKMUTEX$PSDL_MUTEX$$LONGINT in sdl.o   "_SDL_CreateRGBSurface", referenced from:       _SDL_SDL_ALLOCSURFACE$crcE30B3586 in sdl.o ld: symbol(s) not found An error occurred while linking Error: Error while linking ---------------------------------------------------------------------- Ant_222 · 2009-01-21 13:35 When using {$linklib SDLmain} it says it cannot find the library. Try to fix it.. EDIT: I have compiled and attached libSDLmain.a but it still doesn't see those symbols. ---------------------------------------------------------------------- Ant_222 · 2009-01-21 15:02 Now it links (I forgot to add SDL Framework to compiler options), but the program exists with exception class: "External: SIGTRAP" ((( ---------------------------------------------------------------------- Phil · 2009-01-22 15:41 Can you compile with Display Line Numbers (-gl) and run your app in the debugger and do a backtrace to find where the error occurs. Note you may need to recompile SDL with -gl if the error is occuring there. Thanks. -Phil ---------------------------------------------------------------------- Ant_222 · 2009-01-22 16:04 Hello Phil, I'll do as you say, but for now I want to say that my programs work with XCODE, so I suppose the problem should be rooted in the Lazarus IDE. And I'd surely prefer to use Lazarus. Anton ---------------------------------------------------------------------- Ant_222 · 2009-01-22 18:09 The program crashes at the following line: scr:=SDL_SetVideoMode(640, 480, 0, SDL_SWSURFACE); It was called after SDL_Init(SDL_INIT_VIDEO), which had returned 0 (success); And I don't know how to re-build a framework. Never dealt with frameworks... ---------------------------------------------------------------------- Phil · 2009-01-22 18:32 Googling this returns lots of hits on your error: SDL_SetVideoMode "os x" A framework is just one or more libraries (e.g., .dylib) in a special folder structure that simplifies linking and versioning. Look at the create_framework_mac.sh script I created for Den's Qt4Intf library that creates a framework for it (Qt4Intf.framework): http://users.telenet.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html I don't know anything about either SDL or JEDI, but I would imagine they have a script somewhere that creates the SDL.framework. Thanks. -Phil ---------------------------------------------------------------------- Ant_222 · 2009-01-22 20:06 I'll try to make the frameworks myself, but that will require some time, whereon I am rather short right now Meanwhile, I want to try easier things. Since everything works fine from within XCODE, I guess the problem might be in the settings of Lazarus/FPC. Is there a way to copy all the settings from one machine to another? Most of the settings must be stored in the project file, so can you send me a minimal working Lazarus project using SDL? Or, maybe, I will send you my not working project so that we can exclude the project settings from the list of suspects? Many thanks for helping, Anton ---------------------------------------------------------------------- Phil · 2009-01-22 20:12 Guess I don't understand why you think this has something to do with the Lazarus IDE. Don't they include a sample or test application with SDL? If so, just compile it from the command line using lazbuild. Not sure what you mean by it runs from XCode. Your Pascal code runs from XCode? Thanks. -Phil ---------------------------------------------------------------------- Ant_222 · 2009-01-22 20:42 ...Yes, after installing the FPC XCode integration kit. The Demo (after I have converted it from the Delphi format, included "-framework sdl" key in linker options, and added paths to SDL sources and .inc files) builds well and exits with the same error. And again at the execution of SetVideoMode... But since I had to convert it from .dpr, the project settings were not saved. So I still cannot be sure... I need a working Lazarus Mac OS X project. ---------------------------------------------------------------------- Phil · 2009-01-22 21:19 For both the executable you create with FPC/XCode and the executable created with Lazarus, do this: otool -L exefile This will tell you what frameworks and other dependencies the executable has. That might give you a clue about why they're behaving differently. Are you creating a console or GUI app with Lazarus? By default it uses the Carbon widgetset, which means the executable will be using the Carbon and GL (?) frameworks (not at my Mac right now). I assume you're able to compile and run successfully a Carbon GUI app with Lazarus. For compile settings, I would make sure Delphi mode is used. Also, I always turn on all checks (-Cirot). Thanks. -Phil ---------------------------------------------------------------------- Ant_222 · 2009-01-22 21:44 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/CoreSe rvices    /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 ---------------------------------------------------------------------- Phil · 2009-01-22 21:52 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 · 2009-01-22 21:54 The same old thing with NOGUI. Also see the EDIT in my previous post. ---------------------------------------------------------------------- Phil · 2009-01-22 22:04 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 · 2009-01-22 22:32 In console I see the same stuff as was mentioned at that forum. QuoteAgain, 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 · 2009-01-24 04:16 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 · 2009-01-24 11:37 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. ---------------------------------------------------------------------- Vincent Snijders · 2009-01-24 12:25 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 · 2009-01-24 16:20 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 · 2009-01-24 20:22 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 ---------------------------------------------------------------------- cybermonkey342 · 2009-06-13 16:29 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. ---------------------------------------------------------------------- Leledumbo · 2009-06-15 05:18 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.