Carbon Interface
From Lazarus-ccr
Deutsch (de) English (en) Français (fr) Japanese (ja)
Contents |
[edit] Introduction
Carbon is a Mac OS native API.
[edit] Other Interfaces
- Lazarus known issues (things that will never be fixed) - A list of interface compatibility issues
- Win32/64 Interface - The winapi interface for Windows 95/98/Me/2K/XP/Vista, but not CE
- GTK1 Interface - The gtk1 for Unixes, Mac OS X, Windows
- GTK2 Interface - The gtk2 for Unixes, Mac OS X, Windows
- Carbon Interface - The Carbon Interface for Mac OS X
- Qt Interface - The Qt 4 Interface for Unixes, Mac OS X and linux-based PDAs
- Windows CE Interface - For Pocket PC and Smartphones
- fpGUI Interface - A widgetset completely written in Object Pascal
- Cocoa Interface - The Cocoa Interface for Mac OS X
[edit] Platform specific Tips
- OS X Programming Tips - Lazarus installation, useful tools, Unix commands, and more...
- WinCE Programming Tips - Using the telephone API, sending SMSes, and more...
- Windows Programming Tips - Desktop Windows programming tips.
[edit] Interfaces Development Articles
- Carbon interface internals - If you want to help improving the Carbon interface
- Windows CE Development Notes - For Pocket PC and Smartphones
- Adding a new interface - How to add a new widget set interface
- LCL Defines - Choosing the right options to recompile LCL
[edit] See also
- Carbon interface FAQ - A list of frequently asked questions about Carbon interface
- Carbon interface internals - If you want to help improving the Carbon interface
[edit] What you need
The Carbon widgetset is now the default widgetset under Mac OS X. For installation instructions see Installing Lazarus on Mac OS X.
[edit] Getting a "carbonproof" Lazarus
Note: If you installed a Lazarus snapshot, you can skip this section and the next since the snapshot includes both the Carbon widgetset source and compiled units for the Carbon widgetset.
- Install SVN for Mac OS X: A good package is provided by Martin Ott. Another option is to install the SVN client using fink. SVN clients with a GUI (graphical user interface) are available from Versiontracker.
- Then follow Installing_Lazarus#Downloading_Lazarus_SVN
- Start Lazarus. The IDE will start with a new project with an empty form. Save this project under a name of your choice. In the following examples we assume this to be /Users/<yourUsername>/pascal/test/project1.lpi
[edit] Compiling Carbon interface via Makefile
Since 0.9.25 carbon is the default widgetset for Mac OS X, so the below is not needed anymore.
Type in terminal:
make lcl LCL_PLATFORM=carbon
[edit] Compiling the Lazarus IDE with the Carbon interface via Makefile
This requires Lazarus 0.9.25 or superior.
Type in terminal:
make all LCL_PLATFORM=carbon OPT="-k-framework -kCarbon -k-framework -kOpenGL"
On Leopard (OS X 10.5.x) you should type:
make all LCL_PLATFORM=carbon OPT="-k-framework -kCarbon -k-framework -kOpenGL -k'-dylib_file' \
-k'/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib'"
As stated on Apple's developer pages: http://developer.apple.com/qa/qa2007/qa1567.html
Important notes about the Carbon IDE
- You must run Lazarus via lazarus.app.
- Make sure your editor is using a mono-font. You can check that on the Editor Options dialog. The "Monaco" font is a good suggestion.
[edit] Compiling the Carbon interface via Lazarus
We now assume your Lazarus directory is located at /Users/<yourUsername>/pascal/lazarus/
- Start Lazarus.
- Set Environment>Environment Options>Files>Lazarus Directory to /Users/<yourUsername>/pascal/lazarus/
- Set Tools>Configure "Build Lazarus"> to
For 0.9.24 add this to your 'Options':
-k-framework -kCarbon -k-framework -kOpenGL
This will prevent unresolved symbols (Carbon-symbols like _ActivateWindow) while linking lazarus.
- Tools>Build Lazarus -- This will compile the Carbon Interface and put the .ppu files into /Users/<yourUsername>/pascal/lazarus/lcl/units/powerpc-darwin and /Users/<yourUsername>/pascal/lazarus/lcl/units/powerpc-darwin/carbon
[edit] Your first native Carbon app
[edit] Compiler Options
Set Project > Compiler Options > Paths > LCL Widget Type to carbon
You should now be able to compile the project without errors. It will create an executable project1, but you cannot focus it. That's because Mac OS X expects some hidden resource files.
Note for OS X 10.5: As discussed in this forum topic, on Leopard you have to add the following linker parameters to your project:
-dylib_file '/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib'
(This parameter is located at Project > Compiler Options > Linker > Pass additional options to the linker)
[edit] Creating the Apple resource files
Note: Since 0.9.25 Lazarus can create application bundles without compiling this tool on your own. The corresponding button is at Project > Project Options... > Create Application Bundle
The command line tool:
Open /Users/<yourUserName>/pascal/lazarus/components/macfiles/examples/createmacapplication.lpi in the IDE. Compile.
Open a Terminal of your choice. Type:
cd /Users/<yourUserName>/pascal/project1/ /Users/<yourUserName>/pascal/lazarus/components/macfiles/examples/createmacapplication project1 ln -s ../../../project1 project1.app/Contents/MacOS/project1
Now you can start the program from IDE (checked option Use Application Bundle for running and debugging (darwin only)) or via its Finder icon or in the native Mac OS X Terminal via "open project1.app"
Tip: There is also a script that creates an app bundle for a GTK executable at OS X Programming Tips. You can modify it to use with a Carbon executable (take out the 4 instructions that start the executable with X11). A slightly improved version of this script for Carbon apps is also available for downloading from here.
[edit] Creating Universal binaries
Lazarus will create an application tuned for a single CPU, for OSX this is either a PowerPC or Intel CPU. You may want to distribute your application as a 'Universal Binary', allowing users that may have either a PowerPC or Intel computer to use the program. To do this, you need to compile two versions of your application: one with PowerPC as the target CPU and one as Intel. Next, you need to stitch these two executables together using the OSX program lipo (installed with the other OSX developer tools required by Lazarus). For example, consider two versions of the application 'myprogram', with the one in the 'ppc' folder compiled for PowerPC, while the one in the 'intel' folder is compiled for Intel CPUs. You can then combin these by running the command
lipo -create ./ppc/myproj ./intel/myproj -output ./myproj
Now, copy the newly created application myproj inside your .app folder.

