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.