Is C standard library function(ex.prinf, scanf) treated as static library function or dynamic library function?
-
1What does it mean for a function to be static or dynamic? – David Heffernan Oct 28 '11 at 8:55
-
I presume they mean 'linkage' – Mitch Wheat Oct 28 '11 at 8:56
-
3This is totally implementation-dependent, could be anything, and even both can be possible under the same implementation depending on a compiler switch. Insofar, impossible to answer, really. My implementation links dynamically with MSVCRT by default, but what does that mean... nothing. – Damon Oct 28 '11 at 8:57
-
1@MitchWheat If that is so then the question amounts to "can you tell me how I linked my program?" ;-) – David Heffernan Oct 28 '11 at 8:57
it depends on how you link your program. you can go both ways. On VS, you can specify either /MT
(static) or /MD
(dynamic). On gcc, you can specify -static-libgcc
flag to link your program against the static library.
Refer to http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html for more info on gcc flags and http://msdn.microsoft.com/en-us/library/abx4dbyh(v=vs.80).aspx for VS.
-
-static-libgcc
is only aboutlibgcc
which isn't the standard C library. You can linklibc.a
instead of usuallibc.so
though. – wRAR Oct 28 '11 at 13:41 -
You should not really care.
And the compiler could even handle some standard function specially, provided it does so according to what the standard defines.
Sometimes GCC does things like that, for instance it might optimize a call to memset to a loop...
If your question is how you linked your program foo
, on GNU/Linux the command ldd foo
answers that.
Cheers.