5

I don't know C, but need to interact with some C files in a project. I'm noticing that some files have .lib extension, while others (which are also supposed to be libraries) have .c and .h files only in a big folder.

  • What's the difference between these libraries.
  • Are the .c and .h folders also libraries.
  • Is the .lib format the official format for libraries and these guys who did .c and .h just lazy or not using best practice?
sameold
  • 18,400
  • 21
  • 63
  • 87

4 Answers4

10

.c and .h files are source code, i.e., text files. In order to "use" them (i.e., execute the code on a computer) you need to compile them into...

a .lib file is the end result, i.e., a binary file. It can be statically lined into another executable and the code run on a computer. This saves you the time of compiling the source if you don't need to.

.lib is just one common extension, but it doesn't really matter what the extension is as long as the file is valid. Point your compiler/linker to the .whatever library file and let 'er rip, it will all work out in the end.

Ed S.
  • 122,712
  • 22
  • 185
  • 265
  • How do ".o" object files extension fall in this classification? are they previous or next step to ".lib" file? EDIT: [This question answers it](https://stackoverflow.com/questions/23615282/object-files-vs-library-files-and-why) – Santropedro Jul 09 '19 at 19:37
  • In fact, the question might be as "Why we use .h at the end?" the answer is the abbreviation form for (.h) is header, we want sources can be found inside of the file of stdio.h for instance. Thanks. – Bay Feb 14 '22 at 13:22
4

C static libraries are usually compiled in .lib on Windows and .a or .so on Linux/Unix. But extension is just a matter of convenience: "do you have that lib in a repo!?"

as to .h and .c they are as valid, but just not compiled.

You can use both approaches without fear, even if the extension is .darthvader

tolitius
  • 22,149
  • 6
  • 70
  • 81
1

Compiler does not care about the extension as long as the file is specified. I name my libraries .a. Commonly, source files are named as .c, and header files as .h. But this just for mere convenience, a compiler will work on any valid source file, no matter the name.

milancurcic
  • 6,202
  • 2
  • 34
  • 47
1

The standard file extension for programs written in C is .c, header files that come with a project carry the extension .h.

.lib is just some programmers choice to name their library file. It usually stands for a compiled binary which can be statically linked into another executable file. Other common file extension are .a and .so (especially on *NIX machines).

halfdan
  • 33,545
  • 8
  • 78
  • 87