views:

104

answers:

5

Hello everyone.

I was wondering about the standard C libraries that contain all the functions/definitions like abs(), cout streams, printf, etc.

I'm familiar with the header files (stdio.h, cmath.h, time.h, etc etc) but there doesn't seem to be any corresponding .lib or .dll anywhere (ie. stdio.lib, time.dll, etc).

Where is the actual code for the functions in these header files? Am I misunderstanding something? Is there like, one huge lib file that contains all the standardized stuff, or one for each header?

Any help appreciated!!

Thanks!

+4  A: 

It depends on the implementation. On Windows, the standard library functionality is in the C and C++ runtime libraries. The C runtime library is always linked in automatically; the C++ runtime library is linked in automatically if you include one of the standard library headers.

James McNellis
A: 

If you mention DLL's, I assume you are using Windows. In this case, there is usually one "runtime" DLL shipped with compiler. With Visual C++, I believe the name is msvcrt.dll or similar.

Miro A.
Program may use more than one dll. It's name is msvcr**.dll, msvcp**.dll. I.e. msvcr80.dll, msvcr90.dll, and so on.
SigTerm
+2  A: 

You generally don't have to explicitly link the C or C++ runtime libraries in. Usually the compiler will call the linker with the correct options to do it for you.

In fact, with gcc, you have to do something to not include the default libraries (such as using -nodefaultlibs, -nostdlib or -nostartfiles).

The actual location of the standard library, including whether or not it's in a single file, is an implementation issue.

paxdiablo
libgcc is not the standard library; it's some implementation-internal code gcc uses for long division and stuff. The standard library is usually called libc.
R..
+3  A: 

If you are on Linux/some variant of UNIX/AIX try using ldd . Just for the fun of trying something new type in ldd `which ls` in your Linux prompt. Here's what I got:

librt.so.1 => /lib/tls/librt.so.1 (0x0084c000)
libacl.so.1 => /lib/libacl.so.1 (0x40022000)
libselinux.so.1 => /lib/libselinux.so.1 (0x00289000)
libc.so.6 => /lib/tls/libc.so.6 (0x00a0b000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x00c57000)
/lib/ld-linux.so.2 (0x009ec000)
libattr.so.1 => /lib/libattr.so.1 (0x40028000)

The paths should tell you where from the shared libraries are being picked up. If you are using Windows, get hold of depends.exe http://www.dependencywalker.com -- excellent tool

Fanatic23
+1  A: 

As Arpan mentioned, you can use ldd (which is in the 'binutils' package) to discover what SO file is actually being used for libc. The most common implementation on Linux systems is the GNU C library, usually called glibc.

Sam Hanes