1

On installing boost library (of which boost graph library is a part), the following has been installed on my computer:

(1) C:\local\boost_1_86_0\boost\graph\header files.hpp
(2) C:\local\boost_1_86_0\lib64-msvc-14.3\boost_graph-vc143-mt-x64-1_86.dll (305 kb size)
(3) C:\local\boost_1_86_0\lib64-msvc-14.3\libboost_graph-vc143-mt-x64-1_86.lib (2897 kb size)
(4) C:\local\boost_1_86_0\lib64-msvc-14.3\libboost_graph-vc143-mt-s-x64-1_86.lib (3191 kb size)

Looking at https://www.boost.org/doc/libs/1_42_0/more/getting_started/windows.html#library-naming, I infer that (3) and (4) are static libraries because they have a lib prefix, while (2) is obviously a dll.

Given that (3) and (4) are already static libraries, what is the need for (4)? According to that documentation, the "Key" of s in a name indicates:

linking statically to the C++ standard library and compiler runtime support libraries.

(Q1) What differentiates (3) and (4)? Is (3) NOT statically linked to C++ standard library and compiler runtime support libraries? If not, how is (3) getting linked to the standard library and runtime support libraries?

(Q2) Given the static libraries' size of 2897 kb and 3191 kb as opposed to the dll size of 305 kb, does this mean that all of the boost graph library code (and all its algorithms, maxflow, dijkstra shortest path, minimum spanning tree, etc.) is contained completely within these files as object files? Suppose I build an application .exe file on one computer by linking statically to (3) or (4) which runs some boost graph algorithm, can I just take the executable along with either (3) or (4), copy it on a new machine which does not have boost installed at all and expect the executable to run fine? Or, because these are static libraries, the executable will already contain the boost graph library algorithm baked into it and therefore one actually just needs the executable and does not even need (3) or (4) either on the new machine?

(Q3) Can one link dynamically (using MSVC /MD compiler flag) to (3) and (4) and can one link statically (using MSVC /MT compiler flag) to (2) or should one only link statically to a static library and link dynamically to a dll?

(Q4) If one does link to (2) [either using /MD and /MT flag], because the linking has been done to a dll, one cannot just take the executable and expect it to run on another machine which does not have this boost installed. Is this correct?

4
  • 1
    Not sure what you are asking since there are several questions. But are you familiar with the Visual C++ runtime libraries and the options available to your application if the system does or does not have them already installed? Maybe the "s" version of boost will run without the VC runtime installed, while the non-"s" version requires the VC runtime to be installed Commented Nov 23 at 13:27
  • Essentially, I am trying to understand what it means for my application to link "statically" with some other library (can this other library have been statically built itself or could this other library have been dynamically built?). Does this mean that all of the code of the other library is "built into" my exe which is now self-sufficient to be run on another computer? Also, I am having trouble understanding what role /MD and /MT play in all of this. Sorry, if this comment is also having multiple subquestions but I have been unable to get clarity in my own mind about this issue for long. Commented Nov 23 at 13:30
  • 1
    I don't know everything about boost's naming conventions so can't give a definite answer there, but /MD means that your application, regardless if you are using boost or not, will require that the machine you are running on has the VC++ redistributables already installed. The /MT option doesn't require this, as yes, the functions that call out to the VC++ runtime will be included in the program. Commented Nov 23 at 13:45
  • 1
    When statically linking you're only pulling in the things you actually use. So might be more efficient for a single exe that doesn't share code with other executables. And it's easier to deploy (no dll hell). Dll's exist to safe disk space by sharing code between executables but do contain binary code even for things that are not used by your executable Commented Nov 23 at 16:14

1 Answer 1

3

(4) is the same as (3) but with some lower level libraries baked in. Most people would not use (4).

because these are static libraries, the executable will already contain the boost graph library algorithm baked into it and therefore one actually just needs the executable and does not even need (3) or (4) either on the new machine?

Correct. Static linking means you deploy the .exe without the separate library files.

should one only link statically to a static library and link dynamically to a dll?

Correct.

Sign up to request clarification or add additional context in comments.

9 Comments

Thank you. Does this not mean that as a consumer, I cannot create an exe with two vendor libraries, one of which is available only as a .dll and the other vendor provides their software as a static library? All of the libraries that my .exe links to has to be all dlls or all static libraries and in case of the former, I should use the /MD switch and in the latter case I should use /MT ?
The reason for the /MD switch is for the lower-level, C++ and C runtime functions will be accessed via msvc*.dll, vcruntime*.dll, etc (these are all part of the VC++ redistributable package). The /MT switch means that all of those functions you find in msvc*.dll, etc. are embedded within your application, thus no need for the VC++ runtime distributables to be installed. Also, you are reading too much into what static libraries are. A static library is nothing more than obj files all packed into a single file. A DLL on the other hand is an actual executable.
Thank you for your patience with me and my queries! In boost case, to Visual Studio IDE, I am merely required to specify the location of header files (additional include directory) and the location of library folder ` C:\local\boost_1_86_0\lib64-msvc-14.3` [under additional library directories]. I do not need to specify anything more. What decides how does my .exe picks from amongst the choice of (2) or (3) or (4) of the OP?
Basically, if you cannot guarantee that your customer has the VC++ runtime installed already, then you have to opt for /MT and not worry about the VC++ redistributable files since everything is self-contained, or you opt for /MD and have your program's installer get (or you instruct your customer to obtain) the VC++ distributables and install them on the customer's machine.
That is, my question is my .exe can only do either all static linking or all dynamic linking only? Or can it mix and match linking statically to static libraries and linking dynamically to .dlls? Are there options that indicate whether to statically or dynamically link to specific libraries?
You can link statically with some libraries and dynamically with others.
Ah, okay. In that case, if my client wants to use my executable, they should have a copy of the libraries I have linked to dynamically (.dll) on their machine. But they do not need a copy of the static libraries my exe has linked against because the libraries I have linked against statically are already baked into my exe. Is this correct inference?
The second one is dubious. One can use 3rd-party DLLs and static runtime, or 3rd-party static libraries and dynamic runtime. There is nothing wrong with either scenario.
@one_Cable - On the other hand, if your customers have other apps installed, like Office for example, they already have the VC++ runtime installed. They might not like to also have a giant .exe file with everything statically linked. Another difference is that the separate runtime DLLs will get automatic security updates on the next patch-Tuesday, your app will not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.