Build Delphi Packages for C++

From RAD Studio
Jump to: navigation, search

Go Up to Clang-enhanced C++ Compilers


The C++ Win64 Modern platform uses COFF format object files and libraries, and when building Delphi packages for C++Builder, you need to ensure that you generate files this toolchain can consume. This requires building twice: once for ELF, and once for COFF.

Objects and static libraries (.a, .lib) and package import libraries (.bpi) are in either COFF format for the Modern toolchain, or ELF format for the legacy toolchain. These are incompatible, and ELF objects/libraries cannot be linked to apps built with the new toolchain; therefore, each must be distributed in separate folders. The $(Platform) environment variable should expand to 'Win64x' when using the Modern toolchain, allowing you to use this environment variable when distributing your package to customer machines, i.e., you can place files appropriately in folders named 'win64' and 'win64x' in the Library path if you use this environment variable.

To create COFF files using the IDE, follow these steps:

  1. Add the Windows 64-bit Modern Platform to your Delphi package project.
  2. Set it to generate C++ files by setting the 'C/C++ Output file generation' to 'Generate all C++Builder files'
  3. Build the Delphi package.

On the command line:

  • Whether you use the -jphne command when you have misc .pas files or -JL for a package, use -jf:coffi to generate COFF-format C++ files.

Unlike other files, the dynamic package itself (.bpl) and the headers (.hpp) compiled by Delphi are compatible with both formats simultaneously. Only objects and static libraries or the package import library are format-dependent.

However, a package (.bpl) built with the legacy Win64 compiler cannot be used with an app built with the Modern Win64 compiler, and vice versa. Delphi-origin packages are compatible with both, but C++-origin packages must only be used by the same toolchain that created them.


For more details, refer to the table below.

Win64/ELF Win64 (Modern)/COFF Description
Package Build Command dcc64 -JL package.dpk dcc64 -JL -jf:coffi package.dpk
Identical Files Shared between Platforms .hpp and .bpl .hpp and .bpl The .hpp and .bpl produced here are interchangeable.
These can be in a folder that is shared between the two platforms that target Windows 64-bit.
Platform Specific Files
.a and .bpi .lib and .bpi * Use the .a and .lib files when linking statically.
* Use the .bpi when linking dynamically.
These files must be kept separate for the two platforms.

Enabling Components

When users are using the Windows 64-bit Modern C++ platform, they may see the components greyed out in the Palette view. Yet switching to the legacy Win64 C++ platform will re-enable them, allowing them to be placed on a form.

This is due to the information that tells the IDE which platforms a component is valid for:

  • By default, the IDE generates a resource named PLATFORMTARGETS which contains bits that indicate which platforms were enabled for the package. Our packages do this. This is based on the platforms enabled in the project.
    • If seeing the above issue with components, rebuild your package with the Windows 64-bit Modern platform enabled in the project. (It does not have to be the active platform, merely added to (in our terminology, 'enabled for') the project.)
  • The component class can have the ComponentPlatforms attribute on it. Many third party vendors do this because it gives you more control over the setting and does not require you enable additional platforms in the package project.
    • If seeing the above issue with components, update the attribute to include pidwin64x.

See Also