Does unnecessary C++ code end up in my completed program?

Viewed 59

Let's say I'm including a header file that has tons of functions.

#include "1000Functions.h"

Function1(42);
Function2("Hello");
Function1000("geeks!");

But, I just want to use a few of the functions from the header. After preprocessing, compiling, and linking (for example, with g++), would my program include all 1000 functions, or just the 3 that I used?

1 Answers

I found this article that was useful. Using objdump -tC ProgramName can show you the unnecessary code that ends up being loaded into .text when your program is loaded into the memory.

Link-time optimization was what I was looking for, which worked for me once I added both of these tags to the linking command, not just -flto.

-O2 -flto
Related