sameold
sameold

Reputation: 19242

Must C libraries have .lib extension

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.

Upvotes: 5

Views: 3470

Answers (4)

tolitius
tolitius

Reputation: 22519

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

Upvotes: 4

halfdan
halfdan

Reputation: 34214

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).

Upvotes: 1

Ed Swangren
Ed Swangren

Reputation: 124692

.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.

Upvotes: 10

milancurcic
milancurcic

Reputation: 6241

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.

Upvotes: 1

Related Questions