what is libc? what are the functions it includes? how can we get the source code of it?
Asked Answered
P

1

9

As per Wikipedia there are many variants of standard C library based on operating system and compilers. Ref: http://en.wikipedia.org/wiki/C_standard_library

  1. But I want to understand that how plenty of functions which are declared in different headers(eg: stdio.h, string.h, stdlib.h etc. ) are defined in single library. Is the source code file is same for all these header files or there are different libraries for stdio.h, string.h etc? As I am beginner to programming I don't know if multiple source code files can generate a single library like executable. If it is possible then I can understand that libc contains definition of all the standard header files. Where can I see the source code of standard C library?

  2. Is it a static library or dynamic library? If both versions are present in my environment(OS/IDE) which one get linked when I include any standard header file in my source code. Is it IDE dependent? But in case of gcc, programmer does not include libc explicitly.

  3. Is libc a standard name for standard C library?

  4. In windows operating system/environment is it already present or not? If it is present what is the name of it(is it libc only)?

  5. Is there any other standard C library like libm?

Profundity answered 5/12, 2013 at 9:43 Comment(2)
I believe that all of this can be answered by recourse to your favourite search engine. SO doesn't aspire to replace search engines. I'm not convinced you've made a compelling case to have this question, and any answers it draws forth, remain here.Provencher
Please read (The GNU C Library Manual) and (The Linux Programming Interface), and you will get what you want.Cohune
I
5
  1. Generally speaking, a header (.h) file contains the declarations of functions and variables. Implementation files (.c) contain the actual implementation of the declared functions. Since several implementation files can be translated and linked into a single library binary, you can have one library with multiple headers. Many C library implementations are Open Source, and you can look at their source code at their relative project pages. GNU libc and RedHat newlib are the most prominent. I am sure people will add more in comments.

  2. Implementation defined. You can translate the very same sources into either a static or a dynamic library. It is not uncommon to have both versions installed on your system. Since virtually every executable requires libc, it is usually added to the linker input by default so you don't have to add -lc to every command line.

  3. No. The standard name for the standard C library is "The Standard C Library". Note that virtually all implementations of the standard library extend the library with non-standard functions. These remain non-standard, even if they come as part of the standard library. (alloca() springs to mind.)

  4. MSVCRT.dll or somesuch, if I remember correctly.

  5. libm stands for the math section of the standard library, which is not added to the linker input by default as it is seldom required. There is only one standard C library, the one described by the ISO/IEC 9899 language standard (hence the name). There are many other libraries that can readily be assumed to be present on a given system, but only what's described in the ISO/IEC documents is "the standard".

Illjudged answered 5/12, 2013 at 9:53 Comment(4)
With a bit of pride I link to PDCLib, a standard C library implementation project I once started and since passed on to Owen, the new maintainer. It might be interesting to you because it strives to a) provide readily readable source (which GNU libc and newlib fail to deliver IMHO), and b) not add extensions to the library proper unless absolutely necessary. As such, it might not be your first choice for actual employment, but can be interesting for study. No math yet, sorry.Illjudged
Thank you so much DevSolar. Your answer is very helpful. But one more question here is: In point 2 you have mentioned that both versions of library can be present in the system but My question is - in gcc if I call a printf() then would glibc.a be linked or glibc.so?Profundity
@Yash: Usually libc.so is the default, but you can call the compiler with the option -static to compile an all-included executable. Some platforms might support one but not the other, so "it depends" is the only really correct answer. ;)Illjudged
It is worth noting that the standard C library used by Windows is MSVCRT.DLL, but that's now what you link when you use MSVC++. Instead you link to some other DLL, depending of the version of the compiler: MSVCR70.DLL, MSVCR71.DLL... If you use MinGW, however, you'll link to the real MSVCRT.DLL.Carmagnole

© 2022 - 2024 — McMap. All rights reserved.