text data bss dec hex filename
15192 172 672 16036 3ea4 accountant.o
|
text = the executable code and read-only data (such as string constants)
data = initialised data such as
char fileName [21] {"acCOUNTant_state.txt"};
bss = uninitialised and zero-initialised data such as
bool running {false};
dec = the sum of the previous 3 values
hex = the same thing, but in hex.
So after commenting out a couple of Windows specifics like Sleep and MessageBox, I could compile it on Linux.
First comparing local optimisations.
$ g++ -c accountant.cpp
$ size accountant.o
text data bss dec hex filename
16268 61 1089 17418 440a accountant.o
$ g++ -c -O2 accountant.cpp
$ size accountant.o
text data bss dec hex filename
13417 52 1062 14531 38c3 accountant.o
|
These are in line with your observations for the .o file itself.
Now for the whole program:
$ g++ accountant.cpp -lncurses
$ size a.out
text data bss dec hex filename
28713 1440 1448 31601 7b71 a.out
|
Linux images are dynamic linked by default, so all that as been added are the stubs to do the load time linking with the curses and standard libraries.
Using the ldd tool to find out what they are:
$ ldd a.out
linux-vdso.so.1 (0x00007ffd1428f000)
libncurses.so.6 => /lib/x86_64-linux-gnu/libncurses.so.6 (0x00007f2d5d660000)
libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f2d5d630000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f2d5d44e000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2d5d433000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2d5d241000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2d5d23b000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2d5d0ea000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2d5d6b3000)
$ size $(ldd a.out | awk '/=>/ { print $3 }')
text data bss dec hex filename
149855 1700 360 151915 2516b /lib/x86_64-linux-gnu/libncurses.so.6
166341 14652 1152 182145 2c781 /lib/x86_64-linux-gnu/libtinfo.so.6
1895210 51208 13920 1960338 1de992 /lib/x86_64-linux-gnu/libstdc++.so.6
92721 968 680 94369 170a1 /lib/x86_64-linux-gnu/libgcc_s.so.1
1988984 20456 16192 2025632 1ee8a0 /lib/x86_64-linux-gnu/libc.so.6
9175 792 112 10079 275f /lib/x86_64-linux-gnu/libdl.so.2
1358459 900 12 1359371 14be0b /lib/x86_64-linux-gnu/libm.so.6
|
Note that each shared library is only loaded once for all extant processes on a system. So large libraries like libstdc++ that are used widely would not count for much just by running yet another program also using libstdc++. Depending on what you're doing of course, but this program might be the only one using libncurses at any given moment.
> Isn't 600kb of library imports concerningly large?
What is now clear from the above is that you're paying a price for both the C and C++ standard library components.
It's important to note that your program will not continue to grow at this rate.
If you added more of the same code, it would barely budge from this plateau, showing slow steady increases.
If you started using say
std::vector, you might see a smaller step change, and then it would level off again.
FWIW, There isn't anything in your C++ code that couldn't be done in C with some simple modifications.