Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++IDENewsRAD StudioWindows

Dynamic Packages in C++Builder 12.2!

06 dynamic packages in cbuilder 12 2 1600 x 900

RAD Studio 12.2 brings several great improvements to C++. One of these is the completion of the new Windows 64-bit Modern toolchain with the addition of both using and creating dynamic packages (BPL files.)

Dynamic Package Consumption

When we released the new toolchain in RAD Studio 12.1, it fully supported building VCL and FMX apps, as well as using and creating static libraries, DLLs, console apps, and so forth. But VCL & FMX apps make heavy use of packages, which are a kind of DLL with extra metadata. In 12.1, these could only be linked statically. This resulted in a larger executable.

Now, in 12.2, we support linking dynamically to packages just as you’d expect. This means you can build a lighter or smaller EXE, and distribute it alongside the BPL package files.

Shows the'Link with runtime packages' checkbox in the Project Options dialog

Turning this on is very simple: in your project options > Application > Runtime Packages, simply check the ‘Link with runtime packages’ checkbox.

We advise also linking to the dynamic RTL, located in Building > C++ linker > Link with dynamic RTL. These have always needed to be kept in sync – internally, the new toolchain ensures the dynamic RTL is on when using packages regardless of the setting, but it’s good book-keeping to ensure both match.

Creating C++ Packages

A less-used but still important package-related feature is to create packages using C++ source code.

In 12.1, because we only supported linking statically, this feature was not present (static linking to packages is effectively the same as linking in a static library, which was supported.) Now that we have dynamic package consumption, we also support creating packages using C++ source code. This includes mixing C++ and Delphi in one package project.

Lots of Documentation!

Packages are fundamentally a Delphi concept, which is also available to C++. We have often had questions about how they work and how to understand the behaviour of classes inside packages, or the declspec(package) keyword.

Screenshot of a docwiki page about packagesWhen we built packages in 12.2, we used a completely new implementation. This also addressed technical issues with the way packages had been implemented in the legacy Clang compilers: the main issue was around the order of unit initialisation and finalisation, which could result in unexpected AVs when units had cross-unit including cross-package dependencies. This has an entirely new implementation focused on ensuring these scenarios work. But paired with that, we have several new docwiki pages explaining C++ and packages, including our recommended best practices:

  • Packages for the New C++ Toolchain – this is a general index page for the topic. Sub-pages include:
    • Unit Initialization and Finalization – this explains how units are initialised and finalised as a package is loaded or unloaded, and even what this means at all
    • Package Import and Export – this is one of the most important pages to read. It explains how and when types are imported into a packages, or exported from a package. Most confusion around using packages comes from not understanding how this works, or what to do, and we have recommendations for best practices on this page.
    • Using the Weak Packaging directive – weakly packaged units inside packages were already documented, but it ties in to the concepts in the above pages and we have written a more thorough explanation.

It’s done! It’s here!

With dynamic package support, both consumption and production, we have full feature parity with the old legacy Win64 toolchain – and the new one is so much better: better language support, better compatibility, better STL, better linker, better everything.

For this reason, in 12.2 the new Windows 64-bit Modern platform is the default platform for new VCL, FMX and console apps; new DLLs; and new static libraries. We encourage you to migrate to it. The legacy Win64 platform is still installed and available side by side, to assist migration, but it will be removed in a future release. Bcc64x, the new toolchain, is not just the future – but also the present!

 

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

David is an Australian developer, currently living in far-north Europe. He is the senior product manager for C++ at Idera, looking after C++Builder and Visual Assist.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES