There aren't any negative consequences except that your executable might be unnecessarily large. The linker can probably dead strip unused code for you, and that will shrink things back down. You can use some kind of object viewing tool (otool
, objdump
, nm
, etc.) on the output executable to see if your program has extra symbols in it.
I'm using a Mac, so there will be some differences if you're using the standard set of gcc tools, but here's an example:
$ make
gcc -o app main.c file2.c
gcc -Wl,-dead_strip -o app_strip main.c file2.c
$ ls -l app*
-rwxr-xr-x 1 carl staff 8744 Feb 6 20:05 app
-rwxr-xr-x 1 carl staff 8704 Feb 6 20:05 app_strip
I think in the non-Apple gcc world, you would pass -Wl,--gc-sections
instead of the -Wl,-dead_strip
in my example. The size difference in the two executables you can see is due to the extra function being stripped:
$ nm app | cut -c 20- > app.txt
$ nm app_strip | cut -c 20- > app_strip.txt
$ diff app.txt app_strip.txt
8d7
< _function2