How can I compile my C++ app code on Windows? How can I compile Modern C++ code on Windows? How can I compile C++ on Windows with visual UI elements? Let’s answer these questions.
If you are new to programming or even if you coming to C++ from another programming language, sometimes it is hard to understand how to write C_++ code, how to design the screens and how to compile and run your apps. In this post we will explain how to compile C++ code in Windows to produce Modern C++ applications in Windows.
The first thing we need is a modern IDE and C++ Compiler.
Did you know you can download the C++ Builder Community Edition for free?
Embarcadero’s C++ Builder CE, is a free C++ IDE and compiler suitable for the community of freelance developers, startups, students and non-profits, C++Builder Community Edition is a full featured IDE for building iOS and Windows apps from a single modern C++ codebase. It has a limited commercial use license. C++Builder Community Edition includes a code editor, powerful debugging tools, built-in access to popular local databases with live data at design time, Bluetooth and IoT capabilities and a visual UI designer with support for pixel perfect, platform specific styling.
Here are the features of the C++ Builder CE version;
- Build Windows and iOS C++ Applications 10x Faster with less Code.
- C++Builder Community Edition provides you with an integrated toolchain and professional-level developer tools from Day 1
- Featuring Clang-enhanced compiler, Dinkumware standard library, MSBuild/CMake/Ninja support, and popular libraries like Boost and Eigen.
- Develop Windows and iOS applications with a single codebase and responsive UI
- Enjoy the award winning Visual Designer using the C++Builder VCL and FireMonkey frameworks for maximum productivity
- Built-in Debugging Tools that allow you to debug on any device
- Build database apps with local/embedded capabilities
- Hundreds of included components to enhance your app and reduce development cycles
- Direct access to InterBase, SQLite, MySQL, SQL Server, Oracle, PostgreSQL, DB2, SQL Anywhere, Advantage DB, Firebird, Access, Informix, MongoDB, and more.
- Licensed for use until your individual revenue from C++Builder applications or company revenue reaches $5,000 US or your development team expands to more than 5 developers
The C++ Builder CE is the easiest and fastest C & C++ IDE for developing everything from simple to fully professional applications on a wide range of operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files and LSP support. C++ Builder comes with Rapid Application Development Studio, also known as RAD Studio. C++ Builder is one of the most professional IDEs that works under RAD Studio.
You can download the FREE C++ Builder Community Edition (CE) here: https://www.embarcadero.com/products/cbuilder/starter.
Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder. You can download and use the trial version for one month with the same capabilities as the full version . Please visit https://www.embarcadero.com/products/cbuilder.
How to Compile C++ on Windows?
If you download C++ Builder Community Edition (or RAD Studio CE version) or any Professional, Architect, Enterprise versions of C++ Builder. Install it on your Windows machine and run RAD Studio.
- Choose File->New-> “Console Application – C++ Builder” menu
- There will be New Console Application window. Set Target Framework to None for a standard console application and press OK as below
3. Save all Unit File and Project file to a folder.
4. inside the main() function add these lines
1 2 |
std::cout << "Hello LearnCPlusPlus"; getchar(); |
or if you want you can clear all codes there and copy this standard C++ code to run
1 2 3 4 5 6 7 8 9 |
#include <iostream> int main() { std::cout << "Hello LearnCPlusPlus"; getchar(); return 0; } |
This example above is a modern “Hello World” example on Windows which runs with C++ Builder. Modern applications have a GUI and they should be compatible with other operating systems other than just Windows – for C++ Builder this includes MacOS, iOS, and Android. FireMonkey projects are multi device, multi-platform, applications that you can compile and run on Windows, MacOS, iOS and Android.
5. Now you can compile this C++ code in Windows, press F9 key or just press Run button in the center of top bar.
6. You should see this below in a console application
1 |
Hello LearnCPlusPlus |
7. Note that C++ is case sensitive, so upper and lower characters should be also same.
8. Then press F9 key or just press Run button in the center of top bar.
Is there an example of how to create a Modern C++ “Hello World” example?
If you are a beginner “Hello World” examples are good to understand feature of that programming language. It helps explain how to edit text, how to write code in the new language, how to compile and link, how to debug and execute, and how to deploy or release. Now let’s create a Visual and Modern C++ Example
- Open C++ Builder or RAD Studio IDE
- Create a new MultiDevice Application in C++ Builder from File->New menu. This will allow you to develop multi-OS C++ apps with FireMonkey UI elements. Or you can create a new Windows VCL Application in C++ Builder. This will allow you develop C++ apps with VCL UI elements.
- Save all units and project files with “HelloWorld_” prefix in a HelloWorld folder.
- Add Memo (TMemo) and a Button (TButton) from the Palette to your Form. TMemo component is good to display all outputs as in console applications.
- Double click to Button to create OnClick() event, inside that Button1Click event write lines as given full example below,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <fmx.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.fmx" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { UnicodeString ustr; ustr.printf(L"Hello, Pi is %8.3f",M_PI); Memo1->Lines->Add(ustr); } |
7. Run project by hitting F9 or click to Run with Debugging
Output should be like this.
8. If all is fine then save the project
9. if you check your header file you will see all your objects (Memo, Button etc. ) are automatically defined as below. You don’t need to change anything here
If you are a beginner “Hello World” examples are good to understand features of that programming language. It is good to understand how to edit text, how to write in its format, how to compile and link, how to debug and execute, how to deploy or release.
The code below is a modern “Hello World” example on Windows which runs with C++ Builder. Modern applications have a GUI and they should be compatible with other operating systems (Windows, MacOS, iOS, Android). FireMonkey projects are Multi Device (multi-platform) applications that you can compile and run on Windows, MacOS, iOS and Android.
If you want, you can switch to your header file (.h) of your cpp file (.cpp) from the button tabs. Your auto-generated header file of your Multi-Device Application will be shown as below,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#ifndef HelloWorld_Unit1H #define HelloWorld_Unit1H //--------------------------------------------------------------------------- #include <System.Classes.hpp> #include <FMX.Controls.hpp> #include <FMX.Forms.hpp> #include <FMX.Controls.Presentation.hpp> #include <FMX.Memo.hpp> #include <FMX.Memo.Types.hpp> #include <FMX.ScrollBox.hpp> #include <FMX.StdCtrls.hpp> #include <FMX.Types.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TMemo *Memo1; TButton *Button1; void __fastcall Button1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif |
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.
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition