Recent

Author Topic: Apps and App Bundles in OSX  (Read 10230 times)

kelnihat

  • New Member
  • *
  • Posts: 10
Apps and App Bundles in OSX
« on: February 06, 2013, 05:18:06 am »
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

  • Hero Member
  • *****
  • Posts: 509
Re: Apps and App Bundles in OSX
« Reply #1 on: February 06, 2013, 05:54:27 am »

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

  • New Member
  • *
  • Posts: 10
Re: Apps and App Bundles in OSX
« Reply #2 on: February 06, 2013, 06:15:45 am »
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

  • Hero Member
  • *****
  • Posts: 5363
Re: Apps and App Bundles in OSX
« Reply #3 on: February 06, 2013, 07:28:54 am »
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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

kelnihat

  • New Member
  • *
  • Posts: 10
Re: Apps and App Bundles in OSX
« Reply #4 on: February 06, 2013, 07:52:54 am »
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

  • Hero Member
  • *****
  • Posts: 509
Re: Apps and App Bundles in OSX
« Reply #5 on: February 06, 2013, 08:45:02 am »
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
« Last Edit: February 06, 2013, 08:49:42 am by IndianaJones »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Apps and App Bundles in OSX
« Reply #6 on: February 06, 2013, 09:05:30 am »
Yes, 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.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

kamischi

  • Full Member
  • ***
  • Posts: 177
Re: Apps and App Bundles in OSX
« Reply #7 on: February 06, 2013, 10:21:02 am »
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
fpc 2.6.4, lazarus 1.4.0, Mac OS X, fink

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Apps and App Bundles in OSX
« Reply #8 on: February 06, 2013, 01:03:01 pm »
@BigChimp, my mistake, better saying is afterwards Lion (10.7) the OS supports 64bit.
Thanks for the correction.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1042
    • formatio reticularis
Re: Apps and App Bundles in OSX
« Reply #9 on: February 06, 2013, 07:19:28 pm »

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?
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.6 | FPC 3.0.4 | PPC, Intel, ARM | macOS, Windows, Linux

kelnihat

  • New Member
  • *
  • Posts: 10
Re: Apps and App Bundles in OSX
« Reply #10 on: February 06, 2013, 07:34:44 pm »
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...


...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

  • New Member
  • *
  • Posts: 10
Re: Apps and App Bundles in OSX
« Reply #11 on: February 06, 2013, 07:45:05 pm »

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
« Last Edit: February 06, 2013, 07:47:02 pm by kelnihat »

jwdietrich

  • Hero Member
  • *****
  • Posts: 1042
    • formatio reticularis
Re: Apps and App Bundles in OSX
« Reply #12 on: February 06, 2013, 07:50:33 pm »

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.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.6 | FPC 3.0.4 | PPC, Intel, ARM | macOS, Windows, Linux

kelnihat

  • New Member
  • *
  • Posts: 10
Re: Apps and App Bundles in OSX
« Reply #13 on: February 06, 2013, 09:38:19 pm »
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
« Last Edit: February 06, 2013, 09:41:12 pm by kelnihat »

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Apps and App Bundles in OSX
« Reply #14 on: February 06, 2013, 09:44:10 pm »
@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 <ctrl>+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.