Objective
The Boost Library covers a wide range of strings and text-processing related sub libraries such as the format library and the RegExp library, with container-related sub libraries such as a Variant library (and Qt qvariant), and an iterator sub library such as a Tokenizer library (you can take a character t Okenize), there are algorithms, function objects and High-order programming-related sub libraries such as functional libraries, lambda libraries and signal libraries, as well as generic programming, template programming libraries such as call traits, MPL, and concurrent programming-related thread libraries, and so on.
Boost is so powerful that there is no doubt that it is also big. Installing boost on Windows takes up 2g+ space and is cumbersome to compile and configure.
This article discusses how to use the Boost library without configuring the boost library.
The solution is in one sentence:
Cut the boost library and embed the boost source in the project, leaving the project dependent on the boost library.
The meaning of boost library clipping is illustrated by an example
Maybe you still don't understand what the boost library clipping means, let's run an example together. In my cmake-templates inside of a boost code for example, the source only a main.cpp, which only the following lines:
#include <cstdio>
#include <boost/date_time/posix_time/posix_time_types.hpp>
int main (void)
{
Namespace pt = boost::p osix_time;
PT::p Time now = Pt::second_clock::local_time ();
printf ("%s\t->\t%04d-%02d-%02d%02d:%02d:%02d\n"
, "date ' +%y-%m-%d%h:%m:%s '"
, (int) now.date (). Year ()
, (int) now.date (). Month ()
, (int) now.date (). Day ()
, (int) now.time_of_day (). Hours ()
, (int) Now.time_of_day (). Minutes ()
, (int) now.time_of_day (). seconds ());
return 0;
}
The program running output is probably:
Date ' +%y-%m-%d%h:%m:%s '-> 2016-07-11 19:33:19
This 20-line code shows the effect of the next common instruction on the Linux system to date
output the current time (equivalent to the command line input date '+%Y-%m-%d %H:%M:%S'
).
If your system is configured with Boost, then go to the link above to download the source code, into the Boost folder, there are three files: a main.cpp, a CMakeLists.txt, a README description document.
But it's not easy to run this program, especially on a Windows system where everything is handmade: you have to download the appropriate boost version yourself and set some environment variables.
Under Linux is relatively simple, as long as three steps (first download source code, and CD to the source directory):
sudo apt-get install-y libboost-all-dev cmake
mkdir build && CD build
cmake ... && make && ./boost
You can't help feeling, in order to run a 20-line small program, incredibly to manually install the two or three G boost library!
At this time boost library cutting, it is particularly important. We don't want the people who get the code to take the time to configure the boost library, and we don't want our code to be very careful to run. We need to get our code running quickly, no matter what!
After we cropped up the boost library, the header file probably has a 3.18 mb,cpp file with two KB. It looks big, but it's actually 213 kb! after the compression. Get this code, first unzip the Include.zip to the current folder, then run CMake build VS engineering (or Linux makefile Engineering), and then compile and run. There is no need to worry about the configuration of the boost library!
I'm sure you'll be able to run the program. No matter what operating system you use, what compiler you use.
Run up more worry, this is the meaning of boost library clipping.
How do I cut out the part I need?
Let's delve into how to get the top 3.18 MB header file, one KB of CPP files.
First, download the Boost Library source code, you can go to the official website. We only need the official release of the source in the Boost and Libs folders under the things, so I suggest you download my backup. Because it's really much smaller and faster to download. And it's packed with tools for extracting boost source BCP1.
Then, unzip the downloaded compressed package, enter the source folder, create a new folder, such as called output
, and then open the command line in the current window, enter ./bcp.exe boost/date_time/posix_time/posix_time_types.hpp output
, here "./bcp.exe" is our cutting tool, "boost/date_time/posix_time/ POSIX_TIME_TYPES.HPP "is the boost header file that we use in our own projects, and if there are multiple headers, separate them with spaces and knock them all into the command line. 2 The final "output" is the Export folder.
In CMake, this process is probably
1 Create a new include folder in the source root directory, plus the CMakeLists.txt in the root directory include_directories( ${CMAKE_SOURCE_DIR} );
2 New Libs folder, the cropped CPP file into the file under the Miniboost file Plus, and then reference district10/bcp-example-1/libs write Cmakelists file, and then to the root directory of the cmakelists text Pieces plus add_subdirectory (LIBS), 3) will be cropped out of the miniboost link to our binary: target_link_libraries( ${PROJECT_NAME} MiniBoost )
.
You can take a closer look at the difference and connection between the Boost library that the link system installs and the cropped boost library that uses it (which I call miniboost)
Note: one need to be aware of is that the extracted header file, the contents of the BOOST/CONFIG/AUTO_LINK.HPP best deleted, otherwise on the Windows platform, boost will try to automatically link. So I usually empty the contents of this file.
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can help, if there is doubt you can message exchange.