C++Introduction to C++Language FeatureLearn C++

How to Create a New Windows FMX Static Library In C++

In this post, you’ll get answers to these questions:

  • What is Static Library?
  • What is DLL? How do I create a new DLL Dynamic Library?
  • Can I create a new DLL using FMX framework?
  • How can I create a function in a Dynamic Library?
  • Where can I find a simple DLL example for C++ Builder FMX?
  • Can we develop Dynamic Link Libraries in C++ Builder for Windows FireMonkey Applications?
  • Is it possible to use DLLs in multi-device applications?

By learning how to create a new Windows FMX Static Library in c++, and how to compile c++ in windows. It will help you to easily build C++ applications.

What is a library in C and C++?

library in C and C++ is a collection of functions, methods, classes and many other features of C++ exposed for use by other programs. In C++ we can use libraries by adding their header files.

In C++ programming, a library consists of an interface expressed in a .hpp file (header) and an implementation expressed in a .cpp file. This .cpp file might be precompiled as a lib file that can be used with it’s header by other applications.

In C programming, a library consists of an interface expressed in a .h file (“header) and an implementation expressed in a .c file. This .c file might be precompiled as a lib file that can be used with it’s header by other applications.

Both C and C++ library sources and headers are in text forms. When they compiled , compiler generates library files.

What is a Static library in C and C++?

Static Library is a C or C++ library that can be used by other applications sources in compilations. Standard C++ libraries are good example to static libraries. Static library is a part of your application when you compile your application. That means, if you are using a static library, it costs a memory whatever you use or not. Compiler compiles static library every time you compile them. Thus, we should be careful about static libraries to avoid using extra memory and having extra file size.

What is a dynamic link library (DLL)?

Dynamic Link Libraries (DLLs) are modules of compiled code that work in conjunction with an executable to provide functionality to an application. There are two typical uses of dynamic link libraries. The first is to use a repository of external DLLs written by a third party (for example, Microsoft). The second is to write your own DLLs that you want to share between your programs, and another application in a different programming language.

How to Create a new static library?

1. We can create a new DLL by using File -> New -> C++ Builder menu,

How to Create a New Windows FMX Static Library In C++ create new static library

2. Select Static Library, and press “OK” Save all to a folder (i.e. “MyStaticLibrary”)

3. Now we need a Unit to hold our functions, classes , methods and properties etc. Add New Unit from File->New->Unit C++ Builder

4. Save this as “Static_Library_FMX1.cpp” , now you will have “Static_Library_FMX1.cpp” and “Static_Library_FMX1.cpp” files,

Static_Library_FMX1.cpp will be as below,

Static_Library_FMX1.h will be as below,

5. Note that DLL and your application should have to use the same compiler, so in the Project Options->Compiler Options; Use ‘classic’ Borland Compiler should be checked false, or true in both library and the application that uses this lib. Here let’s use CLANG Compiler. Coding with CLANG Compiler for FMX Multi-Device applications is better for future C++ changes in standards.

Goto Project->Options menu, in Building->C++ Compiler section you will see that Use ‘classic’ Borland Compiler is checked for the static library. Disable it ! That means we will use CLANG compiler. Same option should be used in the applications that uses this .lib

How to Create a New Windows FMX Static Library In C++ compiler choice screen

6. Now let’s add #include <fmx.h> and a new custom function that combines two UnicodeStrings with a “+” to a new UnicodeString. Let’s name this function CombineStr() and lets define it. cpp file of our static library will be as below,

and the header file of our static library will be as below,

7. Now we can Build this function in Debug and Release mods by changing its Build Configuration from the Project Window. Thus our other applications can use these .lib files.

If you have a lot of libs in a directory you can add their path from:

In these examples we used latest RAD Studio 11. Previous versions mostly about same to create a new static library.

Still if you need more examples, for the previous versions, you can check this old example video below,

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


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

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?