Apps and App Bundles in OSX lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- kelnihat · 2013-02-06 04:18 Folks, please bear with me; I am trying to help my 13 yer old learn programming with the limited knowledge I have. And forgive me if I am writing in a forum I do not belong. In the 80s, writing simple code using MacPascal and TurboPascal , and ending up with a standalone application you could drag anywhere (and run by double-clicking) was not a problem (even for beginners like me).  I searched high and low for a simple Pascal compiler that would enable us to do this and failed--the story is long and bitter, so I will skip it. I tried doing this with XCode for a while and gave up--too steep a learning curve for me with my limited time.  So now I am trying Lazarus with FPC. After cleaning up everything using the uninstallLaz.sh script provided in the wiki (no, I do not know unix, but can follow directions), and also checking hidden files manually (after making them visble using TinkerTool), I made a clean install of fpcsrc-2.6.0.intel-macosx fpc-2.6.0.intel-macosx lazarus-1.0.4-20121130-i386-macosx on MacOSX 10.6.8 on an Intel core i5 w/ XCode 3.2.6 (1761) and GPC XCode Kit 1.1 (installed for XCode 2.1) So now, we are trying to follow the Lazarus Tutorial series on Youtube, starting with the "hello world" equivalent. Many things work fine--but we are facing problems in the build phase. A typical build yields the following files, accompanied by a "success" message: Success The application bundle was created for "Users/YalcinU/Desktop/LAZARUS APPS/untitled folder/project 1" Here is what is in that folder: backup lib project1 (Unix executable_23.9 MB) project1 (application_12 Kb) project1.ico (windows icon image) project1.lpi project1.lpr project1.lps project1.res unit1.lfm unit1.pas The 12 kb application runs smoothly as long as it is not removed from the folder.  The executable (when run on the Terminal) still gives the error messgae (TCarbonButton.SetFocus Error: SetKeyboardFocus  failed with result -30585), and nothing that looks like an OSX App is created. I searched these forums but could not find anything relevant to our problem except maybe this: >>>>>>>>>>>>>>>>>>>>> Re: launching OS X application « Reply #3 on: November 05, 2011, 09:04:17 am » Quote from: Julius on November 05, 2011, 08:53:50 am     From lazarus I'm running it by clicking "Run" buttont (the green triangle). It works Ok.     From Console window I'm running it clicking project1 from the file manager. Ok, now I see. There is no problem, this is just how Carbon works. Carbon applications *must be run* from the Bundle. You cannot run the executable. To run the Bundle open a terminal and type something like this: cd myproject open project1.app Logged<<<<<<<<<<<<<<< I sort of know that Carbon is old and Cocoa is new , but I cannot interpret what this really means.  Does it mean that at this point in time, I cannot create a genuine standalone app in OSX using Lazarus and FPC? I will be grateful for any light you can shed on our problem. Thanks and regards ---------------------------------------------------------------------- IndianaJones · 2013-02-06 04:54 Yeah, carbon is old but it is still supported on Mountain Lion(10.8.x), so that means you can develop applications on carbon widget. Secondly cocoa is in progress recently, not all the components implemented yet. you can check the status of the widgetsets in here. http://wiki.lazarus.freepascal.org/Roadmap ---------------------------------------------------------------------- kelnihat · 2013-02-06 05:15 Thanks for your response! Not really knowing what a widgetset is (but making what I hope is an educated guess), here is how I interpret it:  I tell the kid that there are things (widgets?) that are missing in current versions of Lazarus/FPC, the lack of which means that we cannot yet create the genuine standalones we had in mind--but the future holds promise.. Did I get it? Regards ---------------------------------------------------------------------- taazz · 2013-02-06 06:28 lcl supports multiple GUI libraries like GTK1, GTK2, Win32, QT, Carbon etc. each library a set of controls like Tedit, Tlistbox, TEditBox called widgets so the library is called widgetset. Carbon is the old MACOS GUI library with COCOA being the new one which is under development. You can build MAC applications today using the Carbon widgetset which they run with out a problem on the current MACS and in the future the cocoa widgetset will be released as well and you can convert your application to it usually with almost no code changes. As for your problem I have never owned a MAC or build a MAC application so sorry I can't be of any help. ---------------------------------------------------------------------- kelnihat · 2013-02-06 06:52 Thanks very much for the welcome correction.  So the version of Lazarus I am using (1.04) uses the Carbon widgets, but should nevertheless be compiling standalones in 10.6.8 (and even Mountain Lion). Why it is not doing so is yet to be resolved... Regards ---------------------------------------------------------------------- IndianaJones · 2013-02-06 07:45 Yes, the version which is 1.0.4 support carbon but not cocoa. Cos Cocoa widgetset is (experimental) 64bit but carbon is 32bit. Have a look at this link for more information. http://wiki.freepascal.org/Cocoa_Interface ---------------------------------------------------------------------- BigChimp · 2013-02-06 08:05 Quote from: IndianaJones on February 06, 2013, 08:45:02 amYes, the version which is 1.0.4 support carbon but not cocoa. Cos Cocoa widgetset is (experimental) 64bit but carbon is 32bit. No, AFAIK, Cocoa is both 32 and 64 bit, see http://en.wikipedia.org/wiki/Cocoa_%28API%29. AFAIR, the process of getting Cocoa widgetset support in Lazarus is still underway. ---------------------------------------------------------------------- kamischi · 2013-02-06 09:21 Dear kelnihat, I have the impression that the discussion about cocoa/carbon is not really hitting your problem. My guess for the origin of your problems how lazarus places the files and folders of your program. The application and the Unix executable are not independent from each other. So, I will try to explain the layout and the relation first and then how to deal with it. Technically the application is a folder named project1.app. This is how all applications are done on Mac OS X. It has a particular directory structure, which is fully described in the Apple Developer documentation. The important point here is that somewhere down in its directory structure most programs usually contain the actual program as a Unix executable. However, Lazarus puts there a link to the Unix executable project1. So, if you double-click the application, the program starts and uses the Unix executable outside the project1.app folder. A sketch of the directory layout with the relevant files: project1 project1.app   Contents     MacOS       project1 -> ../../../project1     ... more stuff ... more stuff This is why starting the Unix executable on its own may not work properly. Also, if you move the application to another place without the Unix executable or move/delete the Unix executable, the application will not work any longer. So, without applying some tricks you will have to move the two project1 together. The way out of this clumsyness is to replace the symlink in MacOS by the Unix executable. Then, you can move the application to other places and even other Macs and it will still run. However, this has another side effect/problem. When you modify your program and build it again, lazarus will only create/replace the Unix executable outside the application folder and not the one in the folder MacOS. So the application will not be changed and act as the old version. You will have to move it there "manually" again. Therefore, it is best not to do this trick before you have finished your development or do it with copies of your application and your executable. Michael ---------------------------------------------------------------------- IndianaJones · 2013-02-06 12:03 @BigChimp, my mistake, better saying is afterwards Lion (10.7) the OS supports 64bit. Thanks for the correction. ---------------------------------------------------------------------- jwdietrich · 2013-02-06 18:19 Quote from: kelnihat on February 06, 2013, 05:18:06 am The 12 kb application runs smoothly as long as it is not removed from the folder.  The executable (when run on the Terminal) still gives the error messgae (TCarbonButton.SetFocus Error: SetKeyboardFocus  failed with result -30585), and nothing that looks like an OSX App is created. I searched these forums but could not find anything relevant to our problem except maybe this: Did you read the threads http://www.lazarus.freepascal.org/index.php/topic,19710.0.html and http://www.lazarus.freepascal.org/index.php/topic,16342.0.html? ---------------------------------------------------------------------- kelnihat · 2013-02-06 18:34 Dear Kamischi, I am grateful for your detailed, informative post--and I thank you for your patience.  I believe I followed everything you wrote. Unfortunately, my ignorance is still an impediment:  I do not know how to... Quote from: kamischi on February 06, 2013, 10:21:02 am ...replace the symlink in MacOS by the Unix executable. Is there some way to do this in the PROJECT OPTIONS/Code Generation dialogue-box (snapshot attached) in Lazarus (e.g., by choosing an option like "Smart Linkable" or "Relocatable"), or do I have to go into the terminal and use Unix commands (sigh!)? Thanks and regards ---------------------------------------------------------------------- kelnihat · 2013-02-06 18:45 Quote from: jwdietrich on February 06, 2013, 07:19:28 pmQuote from: kelnihat on February 06, 2013, 05:18:06 am The 12 kb application runs smoothly as long as it is not removed from the folder.  The executable (when run on the Terminal) still gives the error messgae (TCarbonButton.SetFocus Error: SetKeyboardFocus  failed with result -30585), and nothing that looks like an OSX App is created. I searched these forums but could not find anything relevant to our problem except maybe this: Did you read the threads http://www.lazarus.freepascal.org/index.php/topic,19710.0.html and http://www.lazarus.freepascal.org/index.php/topic,16342.0.html? Yes sir, I did.  The experience was like being pushed from one bureaucrat to another, and ending up with "K" (i.e., Kafka's oops! Apple's iCloud), who would not let me in to his castle.  I am a college teacher and I do my own taxes, but I did not see in that thread a clear answer to the question: "How does one get a standalone OSX app from Lazarus". Thanks and regards ---------------------------------------------------------------------- jwdietrich · 2013-02-06 18:50 Quote from: kelnihat on February 06, 2013, 07:45:05 pmQuote from: jwdietrich on February 06, 2013, 07:19:28 pmQuote from: kelnihat on February 06, 2013, 05:18:06 am The 12 kb application runs smoothly as long as it is not removed from the folder.  The executable (when run on the Terminal) still gives the error messgae (TCarbonButton.SetFocus Error: SetKeyboardFocus  failed with result -30585), and nothing that looks like an OSX App is created. I searched these forums but could not find anything relevant to our problem except maybe this: Did you read the threads http://www.lazarus.freepascal.org/index.php/topic,19710.0.html and http://www.lazarus.freepascal.org/index.php/topic,16342.0.html? Yes sir, I did.  The experience was like being pushed from one bureaucrat to another, and ending up with "K" (i.e., Kafka's oops! Apple's iCloud), who would not let me in to his castle.  I am a college teacher and I do my own taxes, but I did not see in that thread a clear answer to the question: "How does one get a standalone OSX app from Lazarus". Thanks and regards The answer is on the second page of the second thread, available from http://www.lazarus.freepascal.org/index.php/topic,16342.15.html. ---------------------------------------------------------------------- kelnihat · 2013-02-06 20:38 Thank you, jwdietrich--I had missed that because I had no idea that an application was a folder with contents.  My apologies. I switched the alias(?) with the actual executable, and also added an icon together with the couple of lines you provided for to add to the plist, and it all seems to work.  The program runs wherever I put it on my Mac (haven't tried it on an other computer/OS version yet because my son and his computer is at his mother's untill Saturday) (snapshot below): As far as I am concerned, my problem is resolved, and I am grateful to you all for your patience and assistance (and I will make sure the kid is also aware and grateful). However, there is one additional thing I noticed, and in case this is abug or something, I will mention it. When the program is running while displaying the new icon, the icon that shows in the Aplle Dock (rightmost in the dock) is not the same-- it is the generic Lazarus icon. (snapshot attached) Thanks and regards ---------------------------------------------------------------------- IndianaJones · 2013-02-06 20:44 @kelnihat, kamischi explains the structure of the mac application bundle so here is some unix way explanations. Here are the procedures: 1. For example, I compile a Test application, when compiling is over Mac executable file (Test) and bundle directory which is the application name (Test.app) are created. 2. Open a Finder and change the directory where your Test.app directory is. Then +Click shows the "Show Package Contents", choose it. 3. Change the directory to Contents/MacOS as @kamischi said. 4. Delete the link which is 4KByte. 5. Copy the real executable file into this directory, then you have a executable mac bundle. If you encounter any problem feel free to ask. ---------------------------------------------------------------------- IndianaJones · 2013-02-06 20:48 You can choose the icon from the Project/Project Options, if thats the case. ---------------------------------------------------------------------- kamischi · 2013-02-07 09:40 Quote from: kelnihat on February 06, 2013, 09:38:19 pmWhen the program is running while displaying the new icon, the icon that shows in the Aplle Dock (rightmost in the dock) is not the same--it is the generic Lazarus icon.Sometimes it is needed to move the application from one folder to another and back in order to initiate an update of the icon for the Finder or Dock. At least easy enough to give it a try. Michael. ---------------------------------------------------------------------- kelnihat · 2013-02-07 18:37 Thank you for your suggestions InidanaJones, and kamischi.  As I said, this is not vital, but it is always nice to be able to put all one's ducks in a row I tried both suggestions and here is what happens: Moving the file in and out of the folder (and running it in different places) did not seem to work, but I kept it in mind as a "fix" that might come in handy (see below). Loading from the Project Options crashes Lazarus if I try to load a .icn or .icns document; it works if I load a Windows icon (.ico) [I know these only because the excellent graphics program GraphicConventer gives these save options].  The icon shows in the Dock, BUT does not show on the App.  One can force it to show if one subsequently drags an .icns (I also tried w/ ico, does not work) into the Resources folder in the bundle, and adds the magic lines to the plist. Also, one has to move the App in and out of its folder before it does actually show. Maybe a patchquilt solution, but it does work   Grateful for your friendly assistance.  Now if you can also vote me "father of the year"... Regards