G++ offers different options to manage the compilation process according to the requirements. Furthermore, G++ supports different C++ standards which makes it an essential utility in the development ecosystem.
If you also want to know how to install G++ to compile C++ on Fedora Linux, this tutorial is for you. Here, we will explain a simple method to install G++ without hassle.
How to Install G++ on Fedora Linux
Let’s divide this section into multiple parts to describe the various ways to install G++ and then use it to compile C++ on Fedora 38.
Using the Dnf Package Manager
Run the following command to update the Fedora Linux according to the latest one available:
Now, run the following command to install the G++ package:
Once you install G++, check its version through the following command:
Using the Developer Tools
You can install the Developer Tools group which includes G++. Run the following command to install it:
Using the RPM Fusion Repository
RPM Fusion is a third-party software repository which provides additional Fedora Linux packages. Open a terminal and run the following commands to enable the repository:
Once the repository is enabled, run the following command to install G++:
How to Use G++ to Compile C++ on Fedora
Let’s take an example where we create a C++ code and execute it through G++. First, execute the following command to create a C++ file:
Here, we enter the following C++ code to print the “Linux World” as an output:
int main() {
std::cout << "Linux World" << std::endl;
return 0;
}
Now, you need to change the executable permission for the file through the following command:
Once you are done, execute the following given command to compile the C++ program:
In the previous command, the -o option and Linux specify the filename output for the program. Finally, run the following command to execute C++ through G++:
Conclusion
This is all about how you can install and use G++ to compile C++ on Fedora Linux. With G++ on the Linux system, you can compile the C++ programs right from the terminal. Moreover, we included multiple methods to install the G++ utility in the system easily. We also recommend you to use the correct RPM repos. Otherwise, you will face various errors during installation.