Carbon Interface
│ Deutsch (de) │ English (en) │ 日本語 (ja) │
This article applies to macOS only.
See also: Multiplatform Programming Guide
Introduction
Carbon is a Mac OS native API.
Other Interfaces
- Lazarus known issues (things that will never be fixed) - A list of interface compatibility issues
- Win32/64 Interface - The Windows API (formerly Win32 API) interface for Windows 95/98/Me/2000/XP/Vista/10, but not CE
- Windows CE Interface - For Pocket PC and Smartphones
- Carbon Interface - The Carbon 32 bit interface for macOS (deprecated; removed from macOS 10.15)
- Cocoa Interface - The Cocoa 64 bit interface for macOS
- Qt Interface - The Qt4 interface for Unixes, macOS, Windows, and Linux-based PDAs
- Qt5 Interface - The Qt5 interface for Unixes, macOS, Windows, and Linux-based PDAs
- GTK1 Interface - The gtk1 interface for Unixes, macOS (X11), Windows
- GTK2 Interface - The gtk2 interface for Unixes, macOS (X11), Windows
- GTK3 Interface - The gtk3 interface for Unixes, macOS (X11), Windows
- fpGUI Interface - Based on the fpGUI library, which is a cross-platform toolkit completely written in Object Pascal
- Custom Drawn Interface - A cross-platform LCL backend written completely in Object Pascal inside Lazarus. The Lazarus interface to Android.
Platform specific Tips
- Android Programming - For Android smartphones and tablets
- iPhone/iPod development - About using Objective Pascal to develop iOS applications
- FreeBSD Programming Tips - FreeBSD programming tips
- Linux Programming Tips - How to execute particular programming tasks in Linux
- macOS Programming Tips - Lazarus tips, useful tools, Unix commands, and more...
- WinCE Programming Tips - Using the telephone API, sending SMSes, and more...
- Windows Programming Tips - Desktop Windows programming tips
Interface 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
- LCL Internals - Some info about the inner workings of the LCL
- Cocoa Internals - Some info about the inner workings of the Cocoa widgetset
See also
- Carbon interface FAQ - A list of frequently asked questions about Carbon interace
- Carbon interface issues - A list of known compatibility issues with Carbon interface
- Carbon interface internals - If you want to help improving the Carbon interface
What you need
The Carbon widgetset is under development, but isn't yet able to run Lazarus, so we recommend a Lazarus IDE compiled against GTK widgetset on Mac OS X. For instructions see Installing Lazarus on Mac OS X.
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
Compiling Carbon interface via Makefile
Type in terminal:
make lcl LCL_PLATFORM=carbon OPT="-k-framework -kcarbon"
Compiling the Lazarus IDE with the Carbon interface via Makefile (only for alpha-testing)
Type in terminal:
make all LCL_PLATFORM=carbon OPT="-k-framework -kcarbon"
You must run Lazarus via lazarus.app.
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
and add this to your 'Options':
-k-framework -kcarbon
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
Your first native Carbon app
Compiler Options
Set Project > Compiler Options > Paths > LCL Widget Type to carbon
Set Project > Compiler Options > Linking > Options Check Pass Options to the Linker
and type in the edit field:
-framework 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.
Creating the Apple resource files
There is a tool to create these files.
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.