With Gcc 4.8.2, I managed to associate the code without errors with the following:
$ g++ -c main.cpp -O3 -flto $ g++ -c UndefErr.cpp -O3 -flto $ g++ main.o UndefErr.o -flto -O3 -o out
I know that -flto will cause the linker to behave as if -fwhole-program passed, and all this was a single compilation unit. And -fwhole-program , according to the manual, corresponds to the correct use of static functions for functions, therefore excluding an unused function from the output (i.e. you guarantee the compiler that all your functions will not be used by any other code, is possibly dynamically loaded, and the only entry point you guarantee for your users is main() ).
I had to add -O3 , I donβt know exactly why, but the compiler was not very interested in checking functions and eliminating dead code without it.
source share