Packages for C++ New Toolchain
Go Up to C++ Reference
Packages are fundamentally a Delphi concept and do not map perfectly to C++. This imperfect mapping causes issues and complexities when using packages.
For example, Delphi has the concept of units: a .pas file. C++ has translation units, but they are not the same thing. Code can exist in a header and not belong to any specific .cpp file.
To apply this, you must use #pragma package(smart_init) in a unit. Effectively, this marks a compilation unit as a Delphi-style unit (as close as the concepts can be mapped) in the sense ‘unit’ is used in this document and related articles.
Please review the following sections for a better understanding of this topic.
Contents
Unit initialization and finalization
In the new toolchain, RAD Studio has put considerable effort into improving how packages work and ensuring consistency in behavior when statically and dynamically linking packages.
For more information, please review the Unit Initialization and Finalization for C++ New Toolchain article.
Package import and export
It can be hard to understand the effect of the PACKAGE or __declspec(package) modifier: please see the Package import and export article where you can find more information on this topic.
Weakly packaged units
In addition, you should be aware of how weakly packaged units differ from normal units.
Compatibility Warning
BPLs (C++ packages) created by the legacy toolchain are incompatible with applications built using the new toolchain and vice-versa. That is, for Windows-64 bit (Modern)
applications, make sure to use C++ packages compiled with Windows-64 bit (Modern)
. In other words, do not mix toolchains for the various files that make up your application.
This limitation only applies to C++ packages since packages built by Delphi are compatible with both toolchains. That is, Delphi-origin packages can be consumed by Win64 (legacy) and Win64 Modern. This also works in reverse: Delphi apps can load packages built by either Win64 (legacy) or Win64 Modern. However, the Win64 legacy cannot load packages built by Win64 Modern, and Win64 Modern cannot load packages built by Win64 legacy. When you do so, you will see access violations or other errors.