Boost's auto link mechanism and configuration

Source: Internet
Author: User

When we use boost , if we need to link some libraries , We do not have to manually link, in the final analysis or boost auto_link This mechanism, in the boost Under the auto_link.hpp This folder, basically you can see what macro definition to control the boost to link what library, such as Lib library from the beginning of the library compiled Lib , if there is no Lib start, it is a dynamic library, when installed on the client, we need to bring the corresponding DLL

// // Select linkage opt: // #if (Defined (_dll) | | defined (_rtldll)) && defined (boost_dyn_link)#  define Boost_lib_prefix# elif defined (boost_dyn_link)#  "Mixing a DLL BOOST library with a static runtime is a Rea lly Bad idea ... " #else #   " Lib " #endif

From here we can see that if you do not define _dll or boost_dyn_link, then BOOST will automatically select the static library

But there's a place where the egg hurts, because if you include a boost library header file, like python, then boost will automatically trigger the link, See the following code specifically

#ifdef boost_auto_link_tagged# pragma comment (lib, boost_lib_prefix Boost_stringize (boost_lib_name) boost_lib_ Thread_opt boost_lib_rt_opt". Lib") # ifdef boost_lib_diagnostic# pragma message ("linking to lib file:"Boost_lib_prefix boost_stringize (boost_lib_name) boost_lib_thread_opt boost_lib_rt_opt". Lib") # endif#elifDefined (Boost_auto_link_nomangle)# pragma comment (lib, boost_stringize (boost_lib_name)". Lib") # ifdef boost_lib_diagnostic# pragma message ("linking to lib file:"Boost_stringize (Boost_lib_name)". Lib") # endif#else# pragma comment (lib, boost_lib_prefix Boost_stringize (boost_lib_name)"-"Boost_lib_toolset boost_lib_thread_opt boost_lib_rt_opt"-"Boost_lib_version". Lib") # ifdef boost_lib_diagnostic# pragma message ("linking to lib file:"Boost_lib_prefix boost_stringize (Boost_lib_name)"-"Boost_lib_toolset boost_lib_thread_opt boost_lib_rt_opt"-"Boost_lib_version". Lib") # endif#endif

so in the development of the time we often meet this situation, named a project has been linked to the Lib Python library, but he still go to link python dll Library, this is because you specify in a project to link python Lib library, and because of the C + + include mechanism, as long as you have a file in the other project recursive include contains Python header file, then it triggers this automatic link mechanism, but does not specify a link static library in another project, it will let another project run to link DLL, so we need to define these two macro definitions

Boost_python_static_module

Boost_python_static_lib

In most of the library directory, there will be a config.hpp, which is responsible for the configuration of a single library of some macro definitions, if you need to know which libraries have what configuration, open this file to see it.

Boost's auto link mechanism and configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.