How to remove unused C/C++ symbols with GCC and ld?

For GCC, this is accomplished in two stages: First compile the data but tell the compiler to separate the code into separate sections within the translation unit. This will be done for functions, classes, and external variables by using the following two compiler flags: -fdata-sections -ffunction-sections Link the translation units together using the linker optimization … Read more