Question about libraries, what are they and how to create them

This is a discussion on Question about libraries, what are they and how to create them within the C++ Programming forums, part of the General Programming Boards category; Hi
i have been trying to find out the definition for library, but what i found matches the definition of ...

Question about libraries, what are they and how to create them

i have been trying to find out the definition for library, but what i found matches the definition of an .obj file (A group of functions, objects and variables already converted in machine code).

so whats a library, is it a group of compiled .obj files in one file?? or is this wrong??

and also, how can i create a library and, if the definition above is right, what is the advantage of having a library when we can have the obj files separately (besides organization and portability of course)??

In computer science, a library is a collection of subroutines or classes used to develop software.

So to answer your question, a library can be a group of compiled .obj files. Keep in mind that libraries can be linked both statically and dynamically, i.e. the entire object code from the library can be added into the program's executable at compile time (usually in the form of a .lib file on Windows), or it can be used as needed at runtime (using a DLL).

But really, a Windows library isn't restricted to being a .lib or a DLL. You can distribute source code for a set of functions and call it a "library" and let people figure out how they want to compile it into their project.

Since this is primarily a C/C++ board, a "library" means a collection of object files (.obj or .o depending on platform), grouped into a unit consisting of a binary collection (.lib or .a) and one or more .h files.

A "library" is usually something distributed by a third party, which you make use of in your own program, but larger software projects may themselves be composed of a number of libraries which are all linked at build time to produce a fully functional program. It's a higher level of abstraction, above the function level.

The most familiar example is the standard library, which contains the familiar functions such as printf(), fread(), malloc(), etc. This library is so common that it is linked automatically by most compilers. But it's just a library, like any other.

To put it even more simply, a library is any code you use that you didn't create yourself.

Since this is primarily a C/C++ board, a "library" means a collection of object files (.obj or .o depending on platform), grouped into a unit consisting of a binary collection (.lib or .a) and one or more .h files.

That said, some libraries are available as "header-only" libraries, e.g., some of those from the Boost C++ libraries collection. This is more like the "any code you use that you didn't create yourself" definition.