C++ Considerations for Multi-Device Applications

From RAD Studio
Jump to: navigation, search

Go Up to Considerations for Multi-Device Applications

Stack Alignment Issue on macOS

For macOS applications, all memory data must be stack-aligned on 16-byte boundaries:

Available C/C++ Header Files

RAD Studio provides separate C/C++ header files for different target platforms. These files are located in the $(BDS)\include standard search path.

To use header files from an SDK search path, see Add Remote Path Item or Edit Remote Path Item. For example, on macOS you can add the OpenGL and GLUT libraries, as described in the code example OpenGL Multicolor Tetrahedron (C++). You can manage your SDKs from Tools > Options > Environment Options > SDK Manager.

For Windows

The header files for 32-bit Windows and 64-bit Windows are located in $(BDS)\include\windows.

Subdirectory in
$(BDS)\include\windows
Description
   \crtl C/C++ RTL header files (.h). For more information see C Run-Time Library Reference.
   \fmx FireMonkey machine generated header files (.hpp)
   \rtl Delphi RTL machine generated header files (.hpp)
   \sdk Microsoft Windows SDK header files (.h)
   \vcl VCL machine generated header files (.h and .hpp)

For macOS

The header files for macOS are located on the development PC in $(BDS)\include\osx.

Sub-directory in
$(BDS)\include\osx
Description
   \fmx FireMonkey machine generated header files (.hpp)
   \rtl Delphi RTL machine generated header files (.hpp).

For iOS

The header files for iOS are located on the development PC in $(BDS)\include\ios.

Sub-directory in
$(BDS)\include\ios
Description
   \crtl C/C++ RTL header files (.h). For more information see iOS C RTL.
   \fmx FireMonkey machine generated header files (.hpp)
   \rtl Delphi RTL machine generated header files (.hpp).

For Android

The header files for Android are located on the development PC in $(BDS)\include\android.

Sub-directory in
$(BDS)\include\android
Description
   \crtl C/C++ RTL header files (.h). For more information see Android C RTL.
   \fmx FireMonkey machine generated header files (.hpp)
   \rtl Delphi RTL machine generated header files (.hpp).

Framework Availability on Different Platforms

Using Frameworks

On iOS and Android

The BCCIOSARM/BCCIOSARM64/BCCAARM and LD options related to iOS and Android frameworks are described in the following table:

Tool Option Description
BCCIOSARM, BCCIOSARM64 and BCCAARM C++ compiler for the 32-bit and 64-bit iOS Device, and Android -isysroot Specifies the root of the iOS SDK and Android NDK. This is typically set to %IOS_SDK_ROOT% or %ANDROID_NDK_ROOT%.
BCCIOSARM and BCCIOSARM64 C++ compiler for the 32-bit and 64-bit iOS Device -F Specifies the framework path. This is typically set to %IOS_SDK_ROOT%\System\Library\Frameworks".
LD for BCCIOSARM and BCCIOSARM64 32-bit and 64-bit iOS Device -syslibroot Specifies the location of the logical root directory. The logical root directory is a directory on your development PC (Windows) that represents the root of the iOS SDK.
LD for BCCAARM Android --sysroot Specifies the location of the logical root directory. The logical root directory is a directory on your development PC (Windows) that represents the root of the Android NDK.
LD -framework Specifies a framework to link. For example, -framework Foundation links your application to the Foundation framework.

On the IDE, in Project > Options > C++ Compiler > Directories and Conditionals, you can use the "Framework root directories" project option to define directories to add to the framework include path.

String Literals char16_t and wchar_t on macOS and iOS

On macOS and iOS, char16_t is not equivalent to wchar_t (as it is on Windows):

  • On Windows, wchar_t and char16_t are both double-byte characters.
  • On macOS, iOS, and Android, however, a wchar_t is a 4-byte character.

So, to declare UTF-16 constant strings, on Windows use either the L or the u prefix, whereas on macOS, iOS, and Android, use the u prefix.

Example on Windows:

UnicodeString(L"Text"), UnicodeString(u"Text")

Example on macOS, iOS, and Android:

UnicodeString(u"Text")

Using the L prefix for string literals on macOS, iOS, and Android is not, however, wrong. In this case, UTF-32 constant strings are converted to UTF-16 strings.

For portability, use the _D macro to write constant strings that are prefixed accordingly with L or u. Example:

UnicodeString(_D("Text"))

For information about the mobile platforms, see Resolving Linker Warnings about String Literals.

Topics

See Also