Dudearoo
Useing Code::Blocks

Are Programs Dependt on There Library'sI've Wonderd This For Some Time, and I would Love to know this because one of the main reasons i Love C++ is That all its Library's are Basic In the Users Computer, now I want To Download the Boost Librarys but i want to know if my Users will require to have to Download it too, or if i dont have to wory due to the Program compiled with its needed Librarys.

This might be a Easy Question to you guys, but not so to me, i've been googleing around and have found Nothing, Thanks in advance for the Answers :)

Member Avatar for iamthwee

No, if you compile to an exe and plan to deploy on say microsoft os's then no it won't matter.

It depends. There are generally three kinds of libraries in C++: shared libraries, static libraries and header-only libraries.

In the classic plain C++ world (e.g., basic OOP code, no template), the library will be made up of header files that declare classes and functions, and corresponding source files that implement the functions and classes. If you want other people to use the library without having to import all the source files into their "project" (e.g., the list of source files in your IDE), then you need to compile all the source files into a library, which can be either static or shared (also called "dynamic-link library" in Windows lingo).

A static library is essentially just a raw collection of compiled code (i.e., each source file is compiled separately into an object file (.o or .obj extension, usually), and then they are collected together in one static library file). A user of the library would write his code, including the headers from your library, and link to that static library (i.e., to fetch the compiled code that implements the functions he uses). With a static library, the linker will grab all the relevant compiled code from the static library and copy it into the user's executable. At this point, the executable is entirely standalone and does not require the users of that application to have the library installed on their computer.

For a shared library (or dynamic link library (DLL)), the library is technically-speaking more like an executable than like a static library. The compiled code from the library is packaged into a shared library much in the same way as code is packaged into an executable, except there is no main() function (although there can be entry- and exit-point functions in a shared library too). When the linker links a shared library to the user's program, it does not pull the compiled code into the final executable, instead, it inserts code that will, upon loading of the executable, load up the shared library and fill in a set of function pointers corresponding to each function in the library such that when the executable runs it can call the functions of the shared library. That is also why shared libraries are called dynamic-link libraries, because the links between the caller (executable) and callee (library) are made dynamically (at run-time). At this point, the executable is dependent on the availability of that shared library on the system on which it is running. This is also why they are sometimes called "runtime libraries". The user of the application doesn't need to have the entire library installed on his computer (with headers and all), just the shared libraries or DLLs. The code that loads the shared libraries or DLLs is usually configured to look for the library in the current path of the executable (and any directory below it, or user-specified) and in standard system directories (like "system" or "system32" on Windows, or /usr/lib/ or /lib/ on Unix-like systems).

As for header-only library, this is mostly for libraries that are heavily templated (like most of the Boost libraries) which cannot pre-compile the code (because templates are compiled only when used, instantiated). In this case, there is no run-time dependency at all, much like when linking to a static library. The executable produced are entire standalone.

For the C and C++ standard libraries, compilers typically offer both the static and shared library option, and it is usually shared library (or DLL) by default because those shared libraries are very fundamental parts of any system, so they are almost always present. Additionally, the C++ STL is entirely templated and is thus mostly a header-only library on most implementations.

For Boost, most of its sub-libraries are header-only, so it is likely that you won't even have to link to anything, only have to include the headers, leading to a standalone executable. However, some of them require linking to a compiled library (e.g., Date-Time, Thread, Random, Serialization, and a few others), in which case they offer both the static and shared library options, so you pick was suits you.

Thank You iamthwee and especially to mike_2000_17 for you guys on the Feed back, i was in fact considering to do Multithreading with the Boost Library's due to the it being so efficient. Thanks Again and you guys, and Up a reputation point for the both of you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.