For simple test project, g++
or make
standalone are good options as already answered:
g++ -o hi hi.cpp
or
make hi
For real projects, however, the usage of a project manager is required. At the time I write this answer, the most used and open-source is cmake
(an alternative could be QT qmake ).
Following is a simple CMake example:
Make sure you installed cmake
on your linux distribution apt-get install cmake
or yum install cmake
.
Create a file CMakeLists.txt
(the name is important) together with your source hi.cpp
project("hi")
add_executable( hi hi.cpp )
Then compile and run as:
cmake .
make
./hi
This allows the project to scale easily with libraries, sources, and much more. It also makes most IDEs to understand the project properly (Most IDEs accept CMake natively, like kdevelop, qtCreator, etc..)
You could also generate Visual-Studio or XCode projects from CMake, in case you decide to port the software to other platforms in the future.
cmake -G Xcode . #will generate `hi.xcodeproj` you can load on macOS