How I've Been Compiling on Fedora
Compiling is as easy as 1, 2, ...3?
Originally, I was beginning to work on a larger C++ project that used QtCreator and the Qt Framework. Since I've only done Javascript, Python, and a little bit of Golang, I was pretty much in the dark! However, after a few days of reading, I realized that I should be able to get the ball rolling and create some smaller projects.
So I could very easily interact with and begin coding in C++, I scratched the idea of using an IDE currently and run everything from my terminal and Visual Studio Code. To go at a very basic level, ensure you install a compiler. A compiler is something that'll take the code you write and turn it into an executable. I've been using g++ and you should be able to install it by running sudo dnf install gcc-c++
.
Now, for the fun part. After you've opened up Visual Studio Code, create a file titled main.cpp
and paste the code below into it.
#include "iostream"
int main() {
std::cout << "You've done it!\n";
}
Now that main.cpp
exists and you've put code into it. Open your terminal and run g++ main.cpp -o myFirstProgram
. This will create a runnable program called myFirstProgram
. To run the program use the command ./myFirstProgram
and you should get "You've done it!" to appear in your terminal.
[mis@adv examples1]$ g++ main.cpp -o myFirstProject
[mis@adv examples1]$ ./myFirstProject
You've done it!
Now that you're an expert, tell your friends.