Problems with compiling links using boost concurrent programming (multithreading)

Source: Internet
Author: User

When using the boost library, you generally only need to configure the header file path and library file path as programming. In actual programming, general boost knowledge (time, formatting, string processing) is generally not a problem, just pay attention to the namespace import. But for concurrent programming, it is not that simple. This generally involves project property settings, project macro definitions, dynamic library addition, and so on.

The following describes the simplest console project.

1. Create a console project.

Create a console project, add the. cpp file to the project, and add the following code to the file:

# Include <boost/thread. HPP>

Using namespace boost;

Int main ()
{
Mutex mu;

 

Mutex: scoped_lock lock (MU );

Cout <"some operations" <Endl;

 

Return 0;
}

2. compile the project

Compile the project and the following link error will occur:

Fatal error c1189: # error: "compiler threading support is not turned on. Please set the correct command line options for threading: Either/MT/MTD/MD or/MDD"

Solution: Find "Project Properties ----> Configuration properties ----> C/C ++ ----> code generation ----> Runtime Library", and debug the original "single thread (/MLD)" by default) "to" multi-threaded DLL (/MD )".

Re-compile, the following link error will occur:

Fatal error lnk1104: file libboost_thread-vc71-mt-gd-1_36.lib cannot be opened"

Solution: Find "Project Properties ----> Configuration properties ----> C/C ++ ----> pre-processor definition", and fill in the boost_all_dyn_link macro definition.

Re-compile, correct.

Iii. Additional knowledge (/MD, MDD,/mt, MTD)

The 'd' later represents the debug version, and the release version does not have 'D.
/MT is "multithread, static version", which means a static multi-threaded version. After defining it, the compiler calls libcmt. place Lib in the OBJ file to allow the linker to use libcmt. lib processes external symbols.
/MD is "multithread-and DLL-specific version", which indicates the multi-threaded dll version. After defining it, the compiler sets msvcrt. lib is placed in the OBJ file. It is connected to the DLL through a static link. In fact, the working library is msvcr80.dll.

Iv. Boost tutorial

I personally suggest using the book "Full Development Guide for Boost libraries", which can be downloaded from my own csdn resources:

Http://download.csdn.net/detail/wghhdzwzqbx02/4253537

The problem encountered in this article is encountered in Chapter 12th concurrent programming.

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.