Okay, I have a small gap in my knowledge base. When you link a library into your program does the whole library, every function whether you use it or not, get added to your program, or is the linker smart enough so that if you're only using printf that it doesn't add anything but what you need for printf?
Okay, I'm not worried about hello world. Actually it's PDCurses. I just discovered that to get curses to run on my instillation of Code::Blocks that I, in my igorance, made the compiler always link the library for curses. So does this mean that every executable I produce has the entire curses library attached to it, even if I don't #include <curses.h>?
And what about hello world? If all i use is printf in a program are scanf, puts, and the rest hidden in there, dormant and unused?
It depends on the linker, but modern linkers will work like this:
If you're using a shared library, nothing actually gets linked into your executable. It finds the library at runtime and loads it then.
If you're using a static library, only those symbols which you use (and which those symbols use, etc: As you noted, using printf() will likely bring in lots of other related stuff). The whole library will not be attached to your program.
See, that's what I figured, but you can never be sure about these things. I wanted to take PDCurses library out of my linker and see if hello world has any decrease in size. Maybe I will this weekend.
I did, howver, notice, that when I re-write hello world to C++ there was a dramatic increase in the executable. Which is what got me wondering.
g++ and the related library for C++ is pretty bad when it comes to keeping itself down to size. This is mainly due to the iostreams templates dragging in the everything, kitchen sink and all - for example, it drags in printf, which shouldn't be needed for C++ normally.
You can still use a shared library. That way, no stuff will get drawn into your app. Just install the runtime once and poof, everything magically works.
Is there a shared library for PDCurses?