Installation and use of the Boost library on Windows

Time:2024-3-26

catalogs

1. Basic introduction

2、Download and install

3. Configuration boost environment (VS2010)

4. Testing


1. Basic introduction

The Boost library is a number of extensions to the C++ language standard library for theC++A general term for a library of programs, developed and maintained by the Boost community organization. Its purpose is to provide free, peer-reviewed, portable libraries for C++ programmers.The Boost libraries work perfectly well together with the C++ standard library, and provide theextensionsFunction. (Baidu online library

The Boost library contains a large collection of algorithms and function implementations in 20 categories: string and text processing, containers, iterators, algorithms, function objects, and higher-order programming,generalized type (math.)Programming, Template Metaprogramming, Preprocessing Metaprogramming, Concurrent Programming, Math Related, Error Correction and Testing, Data Structures, Input/Output, Cross-Language Support, Memory Related, Syntax Analysis, Miscellaneous. Some of these libraries can be categorized into more than one category.

2、Download and install

First get the boost library, which can be accessed directly in theofficial websiteUp (https://www.boost.org/) download.

Installation and use of the Boost library on Windows

Just choose a version to download locally, here is boost_1_79_0.zip 06-Apr-2022 21:37 186.40 MB

Then unzip the installer to the boost_1_79_0 folder.

Here I need to explain, at first I got the zip unzipped, I thought I could copy it directly to the project directory to include references like the GDAL library. However, I found that the reference file could not be opened.

So the boost library can not be copied directly into the use, or need to compile the static library and reference. The compilation here is a bit different from the installation of GDAL and OpenCV, the compilation and installation here is just to generate the static library under the corresponding file.

Then in the root directory of the boost library (extracted directory boost_1_79_0) under 🙁Graphic visible

1. Double-click the bootstrap.bat file to generate b2.exe;

2. Enter the following command in cmd (not tried) or double click b2.exe to run it.

bjam –toolset=msvc –build-type=complete stage, press enter

The multi-threaded versions of debug and release for the three combinations of –build-type=complete, runtime-link, and link=static, and runtime-link=static are generated, in addition to the single-threaded versions of debug and release. release single-threaded versions are also generated.

3, waiting for the program compilation is complete, about ten minutes to two hours or so, will be in the boost_1_79_0 directory to generate bin.v2 and stage two folders, which bin.v2 is generated under the intermediate files, the size of the 2.4G or so, you can directly delete. stage under the generation of thedll and lib files (not rigorous). The documents are listed below:

Installation and use of the Boost library on Windows

Description:

Here the compilation is done by double clicking on b2.exe, which generates a lib folder under stage by default, which contains only static libraries.
If you want to generate a dll dynamic library, you can . /b2 –help to see the parameter description, and then you need to enter the appropriate compilation command such as:

./b2 toolset=msvc-14.1 link=static runtime-link=shared threading=multi variant=debug
included among these

toolset: Specify the compiler, optional such as minGW, msvc, etc.
vs2017 : msvc-14.1,vs2015 : msvc-14.0, linux :gcc

link: Generate dynamic/static libraries. Generate dynamic link library need to use shared way, generate static link library need to use static way. General boost library may be static way to compile, because the final release of the program with boost dll feeling will be more cumbersome.

runtime-link: Dynamic/static linking of runtime libraries. Again there are both shared and static ways to mark how to link C++ runtime libraries, static if they are included, dynamic if you are using the system runtime libraries.

threading: single/multi-threaded compilation. Generally write multi-threaded programs, of course, to specify the multi way; if you need to write a single-threaded program, then you also need to compile a single-threaded library, you can use the single way.

variant: Compile the debug/release version. Usually the debug version of the program corresponds to the debug version of the library, so compile both.
Then if you need to generate a dll, you can use the link=shared method to generate it. Refer toBoost Compilation and Usage – Knowledgeable

Generate file naming instructions:

  • The version that starts with “lib” is the “link=static” version (static library version, no dlls), while the one that starts directly with “boost” is the The version starting directly with “boost” is the “link=shared” version (the dynamic link library version, which contains both libs and dlls).
  • All libraries contain the “boost” prefix.
  • This is immediately followed by the name of the boost library (e.g. date_time library).
  • Then the compiler version, separated from the library name by a “-” instead of an underscore “_” (e.g. -vc120).
  • The version with “mt” is the “threading=multi” version, and the one without is the “threading=single” version.
  • The version with an “s” is the “runtime-link=static” version, the one without is the “runtime-link=shared” version. The version with “s” is the “runtime-link=static” version and the version without is the “runtime-link=shared” version.
  • The version with “gd” is the debug version, the one without is the release version.
  • All libraries contain the version number ending of the boost library (e.g. 1_56, where “.” is replaced by an underscore “_”)

3. Configuration boost environment (VS2010)

Project->Properties, in the properties dialog that pops up:.

1. Configuration Properties -> VC++ Catalog:

(1) “Containing directory”: the root directory of boost, for example \my_workspace\C_program\C_boost\boost_1_79_0

(2) “Library directory”: the library directory under the stage, for example \my_workspace\C_program\C_boost\boost_1_79_0\stage\lib

2、Configuration Properties->Linker->General Same as the above “library directory”, example \my_workspace\C_program\C_boost\boost_1_79_0\stage\lib

Installation and use of the Boost library on Windows

4. Testing

#include <iostream>
#include <boost/version.hpp>
#include <boost/config.hpp>

using namespace std;
int main()
{
	cout<<BOOST_VERSION<<endl;
	cout<<BOOST_LIB_VERSION<<endl;
	cout<<BOOST_PLATFORM<<endl;
	cout<<BOOST_COMPILER<<endl;
	cout<<BOOST_STDLIB<<endl;
	getchar();
	return 0;
}

Installation and use of the Boost library on Windows

Above the boost library into the vs project, the following can happily call its development to realize their own tasks.

Other Tests

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

#include <boost/timer.hpp>
#include <boost/progress.hpp>

#include <libs/date_time/src/gregorian/greg_names.hpp>
#include <libs/date_time/src/gregorian/greg_month.cpp>
#include <libs/date_time/src/gregorian/gregorian_types.cpp>

#include <boost/date_time/posix_time/posix_time.hpp>

using namespace boost;

int main()
{
	boost::timer t;

	boost::progress_display pd(100);

	for (int i = 0; i < 100; ++i) // Progress bar
	{
		++pd;
	}

	boost :date dt(2009, 12, 8); //date_time library
	assert(dt.year() == 2009);
	assert(dt.day() == 8);
	boost::gregorian::date::ymd_type ymd = dt.year_month_day();
	std::cout<<"\n"<<ymd.year<<"/"<<ymd.month<<"/"<<ymd.day<<" the day is "
		<<dt.day_of_year() <<" days of this year"<< std::endl;

	std::cout << boost :to_iso_extended_string(dt) << std::endl; //convert to another format
	std::cout << boost::gregorian::to_iso_string(dt) << std::endl;
	std::cout << boost::gregorian::to_simple_string(dt) << std::endl<<std::endl;

	// Sorting operations on arrays
	std::vector<int> test_vc(100);
	std::vector<int>::iterator beg_it = test_vc.begin();
	std::vector<int>::iterator end_it = test_vc.end();
	std::srand(std::time(NULL));

	std::for_each(beg_it, end_it, [](int& n){n = rand(); });
	std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " "));
	std::cout << std::endl << std::endl;
	std::sort(beg_it, end_it, std::greater<int>());
	std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " "));
	std::cout << std::endl<<std::endl;

	boost::posix_time::ptime pt(boost::gregorian::date(2005, 2, 6));

	std::cout << t.elapsed() << "s" << std::endl; // program runtime

	system("pause");

	return 0;
}

Installation and use of the Boost library on Windows

Recommended Today

[linux] Permission Understanding

catalogs 1. shell commands and how they work 2. The concept of authority 3. Authority management 2.1 Classification of document visitors (persons) 2.2 File types and access rights (thing attributes) 2.3 Representation of file permission values 2.4 Methods for setting file access rights 3. The file directive 4. Permissions for directories★ 5. Sticky bits★ 6. […]