No need to manually specify input libs for Boost.

2019-08-13 20:19发布

问题:

When using Boost with Visual C++, you can simply include the headers without ever bothering specifying which input libs to link. At build time, the IDE will somehow figure out the appropriate libs to link, be it release or debug, statically linking to CRT or dynamically linking to CRT. This makes using Boost quite convenient. I'm wondering how this is achieved. As an example, with a Multi-threaded Debug DLL (/MDd) configuration, the lib libboost_system-vc80-mt-gd-1_53.lib will be chosen and linked to automatically.

回答1:

The VC++ compiler has a feature that allows you to specify libraries to link directly in source code using pragma directives (https://msdn.microsoft.com/en-us/library/7f0aews7.aspx). It looks something like this:

#pragma comment(lib, "name-of-library")

Boost makes use of this feature, as you can see in this file.