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 OS X

For OS X 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 OS X 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 OS X

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

Sub-directory in
$(BDS)\include\osx
Description
   \crtl C/C++ RTL header files (.h). Some of these files include the C/C++ header files located on Mac in the /usr/include directory. For more information see OS X C RTL.
   \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 OS X

The BCCOSX and XLINK options related to Mac frameworks are described in the following table:

Tool Option Description
BCCOSX, C++ Compiler for OS X --sysroot When the linker is invoked, this option is converted to the -Fr option.
BCCOSX, C++ Compiler for OS X --framework When the linker is invoked, this option is converted to the -Ff option.
XLINK, C++ Cross-Platform Linker -Fr Specifies the location of the logical root directory. The logical root directory is a directory on the local (Windows) machine that represents the root of the remote (OS X) machine.
XLINK, C++ Cross-Platform Linker -Fp Specifies the remote library paths. Also see the -L option.
XLINK, C++ Cross-Platform Linker -Ff Instructs the linker to link the specified framework. For more information, see the --framework documentation.

For a description of how to instruct BCCOSX and XLINK to link to Mac frameworks, see --framework.

For more information on Mac frameworks, see OS X Application Development#Using Frameworks in Mac Apps.

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 OS X and iOS

On OS X 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 OS X, 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 OS X, iOS, and Android, use the u prefix.

Example on Windows:

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

Example on OS X, iOS, and Android:

UnicodeString(u"Text")

Using the L prefix for string literals on OS X, 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