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

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

    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,167
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    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
    21,403
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21