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

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    120

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

    Hi

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

    Tks for your atention

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    19
    'Library' has a pretty broad definition.
    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.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    If you write a few functions that you thought would be useful to others as well, and you post them on cboard so people can copy and paste into their programs, that's a library.

    For a variety of reasons, we usually use more sophisticated ways to distribute those functions, but that's essentially what a library is - a collection of (usually related) functions.

    For example, you can have an XML library that has a bunch of functions that will deal with XML, or a network library that has a bunch of network functions, etc.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by brewbuck
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    120
    Ok i understand now what they are, tks for the quick answer everyone.

Popular pages Recent additions subscribe to a feed