Show: Delphi C++
Display Preferences

Building a Mac OS X Cross-Platform "Hello World" Console Application

From RAD Studio XE2
Jump to: navigation, search

Go Up to Cross-Platform Applications

Go Up to Mac OS X Application Development


This "Hello World" tutorial demonstrates the essential steps for creating a cross-platform application in Delphi or C++. This application uses the OS X platform (the Mac), a console window, an event, and displays a dialog in response to a user action.

Contents

Xcode is Required on Mac

You must have installed Xcode on the Mac computer. RAD Studio requires header files (for compiling) and dynamic libraries (for linking) that are found on Mac in the /usr/include and /System/Library/Frameworks directories.

Steps

To create the cross-platform OS X "Hello World" console application:

Connect your PC to a Mac

See Connecting Your PC to a Mac.

Run the Platform Assistant on the Mac OS X target

  1. The Platform Assistant needs to be running on both the development PC and the target Mac:
    • If the Platform Assistant is already installed on the PC and the Mac, go to the next step.
    • If the Platform Assistant is not yet installed on the PC or Mac, install the Platform Assistant on the target platform. The installer is available to run on the PC or Mac, as follows:
      • To install on the target Mac, use setup_paserver.zip.
      • To install on the PC, use setup_paserver.exe.
      paclient.exe, the Platform Assistant Client Application is installed on your development system when you install RAD Studio.
  2. Open a Terminal window on the Mac.
  3. Change the directory (cd) to the directory that contains the Platform Assistant (PAServer).
  4. Run the Platform Assistant by entering:
    ./paserver
  5. When you are prompted to set a password, enter an optional password string. This is the password that will be required from any remote profile connecting to this instance of the Platform Assistant. To set no password, press Enter.
The Platform Assistant displays a sign-on message and its command prompt (>).

Create a remote profile for the Mac OS X target

  1. Choose Tools > Options > Environment Options > Remote Profiles.
  2. Click Add. The Create a Remote Profile wizard opens.
  3. On the first page of the wizard (Profile information):
    • In Profile name, enter a name for the remote profile.
    • In Platform, select the target platform, in this case OS X.
    • Click Next.
  4. On the second page of the wizard (Host machine information):
    • In Host name, enter the name or the IP address of the target machine. (To see the IP address of the Mac, type ifconfig in the Terminal window and look for the active inet address.)
    • Leave Port number as the default, 64211.
    • In the Password field, enter the optional password string that was set when you started the Platform Assistant that you are connecting to. To search for a password file (*.passfile, created using paserver and containing an encrypted password for sharing with other users), click the ellipsis (...). If no password has been set for the Platform Assistant, leave this field blank.
    • Click Test Connection.
      • If the connection fails, verify the target machine name or IP address (try pinging them on the cmd window), and then ensure that the Platform Assistant is installed and running on the target machine.
      • If the connection succeeds (or fails), click Next.
        Note: You can create a remote profile even if the connection to the target has not yet succeeded. However, a valid remote profile is necessary at several critical times during cross-platform application development, that is, running, debugging, and deploying.
  5. On the third page of the wizard (C++ directory information), do either of the following:
    • For Delphi applications, ignore this page and click Finish unless you want the application to also use C++.
    • For C++ applications, check the checkbox Use this profile with C++ projects. This lists the necessary .dylib and other files. Then click Finish.
  6. For C++ applications, on the Remote Profiles page, click Update Local File Cache to pull all of the specified files (headers and dylibs) from the Mac to the development PC. To include additional libraries or frameworks see Add Remote Path Item or Edit Remote Path Item.
  7. Click OK to close the Remote Profiles dialog box.

Create and configure a cross-platform console application for the Mac OS X target

  1. Choose File > New > Other. The New Items dialog box appears.
  2. Select either Delphi Projects or C++Builder Projects and then double-click Console Application.
  3. For C++ only, in the New Console Application dialog box, make sure that Console application is checked, Target Framework is set to None, and Multi-threaded is unchecked. Then click OK.
  4. In the Project Manager, right-click the Target Platforms node, click Add Platform:
    AddTargetPlatform2.png
  5. On the Select Platform selection box, select OS X, enable the Make the selected platform active checkbox, and click OK:
    SelectPlatform.png
  6. Right-click the OS X platform in the Project Manager to display the following context menu:
    AddActivateOSX.png
    On the context menu, select Assign Remote Profile to assign a remote profile to this platform (the Select Remote Profile dialog box opens).
  7. In the Select Remote Profile for 'OS X' Platform dialog box, select the remote profile that you created for this Hello World application, and click OK. The profile name is now displayed next to the OS X platform in the Project Manager.

Write the code

In the Code Editor modify the code generated from the template:

  1. For C++ only, add after the other #include directives:
    #include <iostream>
  2. Add the code to say hello and wait for the Enter key.
    • For Delphi, enter the following statements in the try block (before the except keyword):
      Writeln('Hello, World!');
      Readln;
    • For C++, enter the following code before the line return 0;:
      std::cout << "Hello, World!" << std::endl;
      std::cin.ignore();
  3. Save and name the application (File > Save).

Run the cross-platform console application on the Mac OS X target

  1. Choose Run > Run Without Debugging.
  2. RAD Studio displays: The project must be compiled before it can be deployed. Continue?. Click Yes.
  3. On the target machine, the "Hello, World!" message is displayed at the Platform Assistant prompt (after messages from the cross-platform debugger). Press the ENTER key. After your cross-platform console application terminates, the Platform Assistant server redisplays its command prompt (>).

Debug the cross-platform application

To debug your cross-platform application in the IDE, use any of the standard Run commands:

  • Run > Run (F9)
  • Run > Step Over (F8)
  • Run > Trace Into (F7)

You can also use the Load Process or the Attach to Process command to start the debugger.

All of these commands:

  • Transfer the required files to the target machine, based on the current assigned profile.
  • Run the application in debug mode.

Using the integrated debugger in the IDE to debug an OS X cross-platform application is very similar to using the integrated debugger to debug a native Win32 application.

If you run your application using a Run command that starts the debugger (such as Run > Run or Run > Step Over or Run > Trace Into), you might be prompted to enter the root password for the Mac in order to give access to the debugger.

See Also

Personal tools
Previous Versions
In other languages