13 N O T E You might want to alias the cumbersome x86_64-pc-linux-gnu-gcc-8.1.0 to some- thing like g++8 , for example, using a command like this: $
sudo ln -s /usr/local/bin/x86_64-pc-linux-gnu-gcc-8.1.0 /usr/local/bin/g++8 13. Navigate to the directory where you’ve saved main.cpp and compile your
program with GCC:
$
x86_64-pc-linux-gnu-gcc-8.1.0 main.cpp -o hello 14. The
-o
flag is optional; it tells the compiler what to name the resulting
program. Because you specified the program name as
hello
, you should
be able to run your program by entering
./hello . If any compiler errors
appear, ensure that you input the program’s text correctly. (The com-
piler errors should help you determine what went wrong.)
Text Editors If you’d rather not work with one of the aforementioned IDEs, you
can write C++ code using a simple text editor like Notepad (Windows),
TextEdit (Mac), or Vim (Linux); however, a number of excellent editors
are designed specifically for C++ development. Choose the environment
that makes you most productive.
If you’re running Windows or macOS, you already have a high-quality,
fully featured IDE at your disposal, namely Visual Studio or Xcode. Linux
options include Qt Creator (https://www.qt.io/ide/), Eclipse CDT (https:// eclipse.org/cdt/), and JetBrains’s CLion (https://www.jetbrains.com/clion/). If
you’re a Vim or Emacs user, you’ll find plenty of C++ plug-ins.
N O T E If cross-platform C++ is important to you, I highly recommend taking a look at Jetbrains’s CLion. Although CLion is a paid product, unlike many of its competitors, at press time Jetbrains does offer reduced-price and free licenses for students and open source project maintainers.