Recent

Author Topic: Newbie to Lazarus - Some Basic Problems  (Read 2776 times)

StephenMilner

  • New Member
  • *
  • Posts: 15
Newbie to Lazarus - Some Basic Problems
« on: January 10, 2022, 04:24:42 pm »
Hi.

Apologies if this is in the wrong sub-forum.

I have installed Lazarus and FPC on a 2021 M1 MacBook Pro following a variety of recipes.

I downloaded the 3 files from here:
https://sourceforge.net/projects/lazarus/files/Lazarus%20macOS%20x86-64/Lazarus%202.2.0/

I used this to compile for ARM:
https://wiki.freepascal.org/macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FApple_Silicon_Support

With the following notes:
1) Before following the instructions I had to cd to /usr/local/share/fpcsrc
2) I did not install Xcode but instead followed these instructions when issuing make commands:
Code: Pascal  [Select][+][-]
  1. Note: If you have only installed the standalone Command Line Tools and not the full Xcode package, you will need to replace /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin with /Library/Developer/CommandLineTools/usr/bin and /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk with /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
3) I needed to sudo every make command to ensure the necessary permissions were there create files/directories etc.
4) This command didn't create a viable link - I had to change the FPC version number to 3.2.2
Code: Pascal  [Select][+][-]
  1. sudo ln -sf /usr/local/lib/fpc/3.3.1/ppca64 /usr/local/bin
5) my .fpc.cfg file contained the references to the Command Line Tools (See 2 above) instead of the ones listed:
Code: Pascal  [Select][+][-]
  1. #include /etc/fpc.cfg
  2. -FD/Library/Developer/CommandLineTools/usr/bin
  3. -XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
  4.  
6) I started the Lazarus IDE and changed the compiler executable to the /usr/local/bin/ppca64 (although after doing so the stored path in the IDE was automatically changed to /usr/local/lib/fpc/3.3.1/ppca64
7) I changed the debugger in the IDE to the LLDB Debugger

I started the Lazarus IDE and created a new Console Application Project and modified it (just the main application loop is shown for brevity):
Code: Pascal  [Select][+][-]
  1. procedure TMyApplication.DoRun;
  2. var
  3.   ErrorMsg: String;
  4. begin
  5.   // quick check parameters
  6.   ErrorMsg:=CheckOptions('h', 'help');
  7.   if ErrorMsg<>'' then begin
  8.     ShowException(Exception.Create(ErrorMsg));
  9.     Terminate;
  10.     Exit;
  11.   end;
  12.  
  13.   // parse parameters
  14.   if HasOption('h', 'help') then begin
  15.     WriteHelp;
  16.     Terminate;
  17.     Exit;
  18.   end;
  19.  
  20.   { add your program here }
  21.   writeln ('Hello World');
  22.   // stop program loop
  23.   Terminate;

Upon selecting Command R the application compiles but the IDE Reports an error: Oooops, the debugger entered the error state. Save your work now ! Hit Stop and hope the best, we're pulling the plug.

However, running the created executable, it does exactly what it says on the tine
Code: Pascal  [Select][+][-]
  1. steve:~/Lazarus/Hello World $ ./Hello_World
  2. Hello World
  3.  

I have selected both the Dwarf 2 with sets and the Dwarf 3 debugger options.

In order to see if this was something I had inadvertently done I created a new Form Module and tried to run it. The compiler generated this error:
Code: Pascal  [Select][+][-]
  1. Compile Project, CPU: aarch64, Target: /Users/steve/tmp/project1: Exit code 1, Errors: 1
  2. Error: resource compiler "fpcres" not found, switching to external mode
  3.  

If I now close all files and re-load my Hello World application, it will no longer compile with the same error. If I close Lazarus, re-open and try and compile the Hello World Application, again I get a the fpcres error. The only way to eliminate it is to delete the Hello World files and create a new Console Application - whereupon I revert back to the debugger error.

If you could give a newbie who's fumbling around in the dark a pointer it would be much appreciated.

Let me know if you need the contents of any config or other files.

Regards,
Stephen

StephenMilner

  • New Member
  • *
  • Posts: 15
Re: Newbie to Lazarus - Some Basic Problems
« Reply #1 on: January 10, 2022, 05:52:56 pm »
OK - So, I've been a bit of a numpty....

I re-read this post properly....

https://wiki.freepascal.org/Installing_Lazarus_on_macOS

The key line here is this....

Code: Pascal  [Select][+][-]
  1. If you are installing FPC 3.2.2 (Lazarus 2.2RC1 or later) then you don't need to compile a native Apple Silicon version because FPC 3.2.2 for macOS is a universal binary containing both Intel and aarch64 executables.

So I compiled the fixes:
https://wiki.freepascal.org/Installing_Lazarus_on_macOS#Lazarus_Fixes_2.2

All good with my Hello World.
Got an error with my Form though, and I'm not entirely sure what I'm doing, but I seem to be getting code mixing up between the 2. If I re-open the Hello World I get the same compiler error - perhaps something to with me adding the unit for the form into the path. I think I can can work this out for myself though.

The error when running the form:
Code: Pascal  [Select][+][-]
  1. Compile Project, Target: project1: Exit code 1, Errors: 4
  2. Error: linker: Undefined symbols for architecture arm64:
  3. Error: linker:   "WSRegisterBevel", referenced from:
  4. Error: ld: symbol(s) not found for architecture arm64
  5. An error occurred while linking
  6. Error: Error while linking
  7.  

I guess I'm missing something...

I't's probably something to do with the LCLWidgetType setting for the project....

The current set is cocoa.

What should I be using?
« Last Edit: January 10, 2022, 06:08:03 pm by StephenMilner »

StephenMilner

  • New Member
  • *
  • Posts: 15
Re: Newbie to Lazarus - Some Basic Problems
« Reply #2 on: January 10, 2022, 06:23:10 pm »
So I worked out what I was doing wrong mixing my code up.

I needed to create a new project for my empty form test, which I've now done.

The compiler is now giving this error when I try and run the new project with a single form in it.

Code: Pascal  [Select][+][-]
  1. Build File /Users/steve/Lazarus/Form/unit1.pas: Exit code 1, Errors: 1
  2. Target OS: Darwin for AArch64
  3. unit1.pas(8,22) Error: Cannot find Forms used by Unit1, incompatible ppu=/Users/steve/bin/lazarus/laz_fixes/lcl/units/aarch64-darwin/forms.ppu, package LCLBase
  4.  

So if anyone can suggest what I'm doing wrong, or more importantly point me in the correct direction so I can read about it myself....

StephenMilner

  • New Member
  • *
  • Posts: 15
Re: Newbie to Lazarus - Some Basic Problems
« Reply #3 on: January 10, 2022, 06:31:09 pm »
And as if by magic, it's started working.

Would I need to Compile/Build before I run?

That's what I've just done and it seems to be fine now.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1988
  • Former Delphi 1-7, 10.2 user
Re: Newbie to Lazarus - Some Basic Problems
« Reply #4 on: January 11, 2022, 12:59:49 am »
The Mac Installation FAQ in the Wiki contains the solutions to, or explanations of, some of the issues you ran into.

Quote
Would I need to Compile/Build before I run?

Run will normally recompile the application if it has any changes. Occasionally you might find you need to build first if no changes are detected.

Run also runs your application using the debugger. Run w/o debugger just runs it normally. I always add a Run w/o icon (green arrow with red cross) to my icon bar especially as M1 computers treat each new compiled version as needing permission to debug.
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.4
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.4

StephenMilner

  • New Member
  • *
  • Posts: 15
Re: Newbie to Lazarus - Some Basic Problems
« Reply #5 on: January 11, 2022, 01:31:14 pm »
Thanks for the pointers!

 

TinyPortal © 2005-2018