Linking C++ applications

As in C, C++ applications typically start from a main() function with the same signatures that C already provides. Also, as in C programs, the actual entry point of the code is actually the _start function.

Unlike in C, however, C++ is far more complicated, including a lot more code for a simple example. To demonstrate this, let's look at a simple Hello World\n example:

#include <iostream>int main(void){    std::cout << "Hello World\n";}// > g++ scratchpad.cpp; ./a.out// Hello World

First and foremost, the C++ application example is slightly longer than the equivalent C example from the previous section:

> gcc scratchpad.c -o c_example> g++ scratchpad.cpp -o cpp_example> stat -c "%s %n" *8352 c_example8768 cpp_example ...

Get Hands-On System Programming with C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.