OpenGLCoreTutorials icon indicating copy to clipboard operation
OpenGLCoreTutorials copied to clipboard

Cannot compile `basic` example on macOS

Open antonc27 opened this issue 1 month ago • 5 comments

When importing basic example in Lazurus 4.2, I have following error:

Image

I did select MacOS in the project options as describedi in the readme:

Image

But when compiling:

Compile package LazOpenGLContext 0.0.1: Exit code 1, Errors: 1, Warnings: 1
Warning: Recompiling LCLType, checksum changed for /opt/homebrew/Cellar/fpc/3.2.2_1/lib/fpc/3.2.2/units/aarch64-darwin/rtl/classes.ppu
openglcontext.pas(99,3) Error: Cannot find LCLType used by OpenGLContext, incompatible ppu=/Users/ac27/dev/lazarus/lcl/units/aarch64-darwin/lcltype.ppu, package LCLBase

Do you know how to fix that?

macOS version: 15.6.1 (24G90) on Apple M1 MacBook Pro Lazurus version: Lazarus 4.2 (rev Unknown) FPC 3.2.2 aarch64-darwin-cocoa FPC: 3.2.2 installed with brew (Free Pascal Compiler version 3.2.2 [2024/09/11] for aarch64)

antonc27 avatar Oct 26 '25 11:10 antonc27

On my MacBook M4 Pro with MacOS 15.6.1 I also get the warning that it is unable to register the component. However, this only influences viewing the form at design time, and the executable runs just fine. Can you make sure you recompiled Lazarus with the LazOpenGLContext package (go to Package/Install/Uninstall Packages menu item), which you could also do from the command line (lazbuild --build-ide= --add-package lazopenglcontext).

I did also edit my /etc/fpc.cfg file as I describe here:

#ifdef cpuaarch64
#IFDEF Darwin
-WM10.15
#ENDIF
#endif
Image

Since the TOpenGLControl can not be shown on MacOS in the Lazarus Form view, an alternative is to create it at run time, and omit it from your form. MRIcroGL shows this strategy:

procedure TGLForm1.FormCreate(Sender: TObject);
begin
...
 ViewGPU1 :=  TOpenGLControl.Create(GLForm1);      
 ViewGPU1.OpenGLMajorVersion:= 3;
 ViewGPU1.OpenGLMinorVersion:= 3;  

My fpc is in /usr/local/bin/fpc not homebrew.

$ file /usr/local/bin/fpc
/usr/local/bin/fpc: Mach-O universal binary with 3 architectures: [i386:
- Mach-O executable i386] [x86_64:Mach-O 64-bit executable x86_64] [arm64]
/usr/local/bin/fpc (for architecture i386):	Mach-O executable i386
/usr/local/bin/fpc (for architecture x86_64):	Mach-O 64-bit executable x86_64
/usr/local/bin/fpc (for architecture arm64):	Mach-O 64-bit executable arm64
$ fpc -v
Free Pascal Compiler version 3.2.2 [2021/05/16] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others

neurolabusc avatar Oct 26 '25 13:10 neurolabusc

Thanks for the help!

I tried to install LazOpenGLContext and rebuild IDE by clicking Rebuild IDE, but it still gives me this error on compilation (i also edited /etc/fpc.cfg as you suggested):

Compile package LazOpenGLContext 0.0.1: Exit code 1, Errors: 1, Warnings: 1
Warning: Recompiling LCLType, checksum changed for /opt/homebrew/Cellar/fpc/3.2.2_1/lib/fpc/3.2.2/units/aarch64-darwin/rtl/classes.ppu
openglcontext.pas(99,3) Error: Cannot find LCLType used by OpenGLContext, incompatible ppu=/Users/ac27/dev/lazarus/lcl/units/aarch64-darwin/lcltype.ppu, package LCLBase

Note that brew FPC is not a universal one:

% file $(which fpc)                                                                            
/opt/homebrew/bin/fpc: Mach-O 64-bit executable arm64

antonc27 avatar Oct 26 '25 16:10 antonc27

this is a full output:

% ./lazbuild --build-ide= --add-package lazopenglcontext
SetPrimaryConfigPath NewValue="/Users/ac27/dev/lazarus/config"
Hint: (lazbuild) Primary config path: "/Users/ac27/dev/lazarus/config"
Hint: (lazarus) [TBuildManager.SetBuildTarget] Old=aarch64-darwin--cocoa New=aarch64-darwin--cocoa Changed: OS/CPU=True LCL=False
Hint: (lazbuild) Adding package "/Users/ac27/dev/lazarus/components/opengl/lazopenglcontext.lpk" to install list of IDE
Hint: (lazbuild) Building Lazarus IDE with profile "Normal IDE"
Hint: (lazarus) [TBuildManager.SetBuildTarget] Old=aarch64-darwin--cocoa New=aarch64-darwin--cocoa Changed: OS/CPU=True LCL=False
Hint: (lazarus) Last compile was incomplete for cocoa_pkg 0.0
  State file="/Users/ac27/dev/lazarus/lcl/interfaces/carbon/pascocoa/lib/aarch64-darwin/cocoa_pkg.compiled"
Hint: (lazarus) Last compile was incomplete for LazOpenGLContext 0.0.1
  State file="/Users/ac27/dev/lazarus/components/opengl/lib/aarch64-darwin/cocoa/lazopenglcontext.compiled"
Info: (lazarus) Execute Title="Compile package cocoa_pkg 0.0"
Info: (lazarus) Working Directory="/Users/ac27/dev/lazarus/lcl/interfaces/carbon/pascocoa/"
Info: (lazarus) Executable="/opt/homebrew/bin/ppca64"
Info: (lazarus) Param[0]="-MObjFPC"
Info: (lazarus) Param[1]="-Scgi"
Info: (lazarus) Param[2]="-O1"
Info: (lazarus) Param[3]="-gw"
Info: (lazarus) Param[4]="-gl"
Info: (lazarus) Param[5]="-l"
Info: (lazarus) Param[6]="-vewnhibq"
Info: (lazarus) Param[7]="-Fi/Users/ac27/dev/lazarus/lcl/interfaces/carbon/pascocoa/foundation"
Info: (lazarus) Param[8]="-Fi/Users/ac27/dev/lazarus/lcl/interfaces/carbon/pascocoa/appkit"
Info: (lazarus) Param[9]="-Fi/Users/ac27/dev/lazarus/lcl/interfaces/carbon/objc"
Info: (lazarus) Param[10]="-Fu/Users/ac27/dev/lazarus/lcl/interfaces/carbon/pascocoa/"
Info: (lazarus) Param[11]="-Fu/Users/ac27/dev/lazarus/lcl/interfaces/carbon/pascocoa/foundation"
Info: (lazarus) Param[12]="-Fu/Users/ac27/dev/lazarus/lcl/interfaces/carbon/pascocoa/appkit"
Info: (lazarus) Param[13]="-Fu/Users/ac27/dev/lazarus/lcl/interfaces/carbon/objc"
Info: (lazarus) Param[14]="-Fu/Users/ac27/dev/lazarus/packager/units/aarch64-darwin"
Info: (lazarus) Param[15]="-FU/Users/ac27/dev/lazarus/lcl/interfaces/carbon/pascocoa/lib/aarch64-darwin/"
Info: (lazarus) Param[16]="cocoa_pkg.pas"
Info: (lazarus) Execute Title="Compile package LazOpenGLContext 0.0.1"
Info: (lazarus) Working Directory="/Users/ac27/dev/lazarus/components/opengl/"
Info: (lazarus) Executable="/opt/homebrew/bin/ppca64"
Info: (lazarus) Param[0]="-MObjFPC"
Info: (lazarus) Param[1]="-Scghi"
Info: (lazarus) Param[2]="-O1"
Info: (lazarus) Param[3]="-gw"
Info: (lazarus) Param[4]="-gl"
Info: (lazarus) Param[5]="-l"
Info: (lazarus) Param[6]="-vewnhibq"
Info: (lazarus) Param[7]="-Fu/Users/ac27/dev/lazarus/components/opengl/"
Info: (lazarus) Param[8]="-Fu/Users/ac27/dev/lazarus/packager/units/aarch64-darwin"
Info: (lazarus) Param[9]="-Fu/Users/ac27/dev/lazarus/components/lazutils/lib/aarch64-darwin"
Info: (lazarus) Param[10]="-Fu/Users/ac27/dev/lazarus/components/freetype/lib/aarch64-darwin"
Info: (lazarus) Param[11]="-Fu/Users/ac27/dev/lazarus/lcl/units/aarch64-darwin"
Info: (lazarus) Param[12]="-Fu/Users/ac27/dev/lazarus/lcl/units/aarch64-darwin/cocoa"
Info: (lazarus) Param[13]="-FU/Users/ac27/dev/lazarus/components/opengl/lib/aarch64-darwin/cocoa/"
Info: (lazarus) Param[14]="-dLCL"
Info: (lazarus) Param[15]="-dLCLcocoa"
Info: (lazarus) Param[16]="lazopenglcontext.pas"
Hint: (11030) Start of reading config file /opt/homebrew/etc/fpc.cfg
Hint: (11031) End of reading config file /opt/homebrew/etc/fpc.cfg
Free Pascal Compiler version 3.2.2 [2024/09/11] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
(1002) Target OS: Darwin for AArch64
(3104) Compiling lazopenglcontext.pas
(3104) Compiling openglcontext.pas
(10001) PPU Loading /Users/ac27/dev/lazarus/lcl/units/aarch64-darwin/lcltype.ppu
(10011) PPU Source: lcltype.pp not found
(10028) Recompiling LCLType, checksum changed for /opt/homebrew/Cellar/fpc/3.2.2_1/lib/fpc/3.2.2/units/aarch64-darwin/rtl/classes.ppu
/Users/ac27/dev/lazarus/components/opengl/openglcontext.pas(99,3) Fatal: (10022) Can't find unit LCLType used by OpenGLContext
Fatal: (1018) Compilation aborted
Error: (lazarus) Compile package LazOpenGLContext 0.0.1: stopped with exit code 1
Hint: (11030) Start of reading config file /opt/homebrew/etc/fpc.cfg
Hint: (11031) End of reading config file /opt/homebrew/etc/fpc.cfg
Free Pascal Compiler version 3.2.2 [2024/09/11] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
(1002) Target OS: Darwin for AArch64
(3104) Compiling cocoa_pkg.pas
(3104) Compiling ./appkit/appkit.pas
(3104) Compiling /Users/ac27/dev/lazarus/lcl/interfaces/carbon/objc/lobjc.pas
/Users/ac27/dev/lazarus/lcl/interfaces/carbon/objc/error.inc(115,25) Hint: (5024) Parameter "code" not used
/Users/ac27/dev/lazarus/lcl/interfaces/carbon/objc/error.inc(115,48) Hint: (5024) Parameter "data1" not used
/Users/ac27/dev/lazarus/lcl/interfaces/carbon/objc/error.inc(115,60) Hint: (5024) Parameter "data2" not used
(9009) Assembling lobjc
Error: (lazarus) Compile package cocoa_pkg 0.0: terminated
Error: (lazarus) [TLazPackageGraph.CompileRequiredPackages] "Exit code 1"
Error: (lazbuild) Building IDE: Compile AutoInstall Packages failed

antonc27 avatar Oct 26 '25 16:10 antonc27

Can I suggest you uninstall fpc from homebrew and install both Lazarus and FPC using the disk images. I can not replicate your issue, but I wonder if this is a matter of file permissions as you need to rebuild some of the libraries. You may also want to check permissions for /Users/ac27/dev/.

neurolabusc avatar Oct 26 '25 19:10 neurolabusc

I realized I had been using Lazarus 4.0, I just downloaded 4.2 from the link I just linked. Now after installing the OpenGL package the "GL" component appears on the "OpenGL" tab and I can see the visual component on the form and adjust properties in the object inspector. It also compiles nicely. Looks like the Lazarus team is making steady progress.

Image

neurolabusc avatar Oct 26 '25 20:10 neurolabusc