Building a subset of boost in windows

2019-01-17 08:04发布

问题:

I'm trying setup a subset of boost and get it properly compiled using bjam, however I'm not getting the result I'm looking for. I'm working on windows using boost 1.37.0.

Let's say I want the libraries smart_ptr and filesystem built/installed. I intentionally chose a header only library and one library needing to compile a library. I want them to be built into a directory structure similar to the one I would get if I built a complete boost installation with bjam (i.e not specifying any --with-libraryX) but of course without all the libraries I'm not interested in.

My first approach was to use the --with-filesystem --with-smart_ptr in bjam, however it seemed like it didn't recognize smart_ptr (I tried smartptr and smart-ptr without success). I guess this is because it's a header only library.

When I removed it and only had --with-filesystem it seemed to copy ALL libraries header files to the install path and only build the libraries for filesystem. The library building behavior was the one I hoped for, but I got tons of header files for libraries I'm not interested in installed in my boost directory.

My second approach was to use bcp to copy the relevant projects. This did work out in the sense that I only got the projects I cared about (and their dependencies). However they didn't provide any make files for building the libraries that was copied. This means I would need to setup projects files for all the libraries that are not header only and manually build them.

So my question is basically, is there a way of selectively building boost that only copies the headers for the libraries I'm interested in and only building library files for the non header only libraries I'm interested in (and the boost libraries they are dependent on course)?

There are probably tons of manual/scripting based solutions for this, but if I could get something running only using bjam would be way more useful for me since adding new libraries or upgrading to a new boost version would be very simple.

EDIT: Added the complete command line for the first approach:

bjam install --prefix=c:\temp\boostsmall 
   --build-dir=C:\temp\boostsmalltemp --layout=system 
   --with-filesystem variant=debug link=static threading=multi
   runtime-link=static

Changed scoped_ptr to smart_ptr

回答1:

Solved it.

The bcp solution had make files for the projects, however I needed to copy the tools directory and the root of the boost directory to the place I copied all my libs to get things up running.



回答2:

Great question! This is an issue I have recently managed to figure out, I think.

I already had the full Boost libraries installed, including the ones requiring separate compilation.

I managed to create a subset of the Boost libraries (regex) for a particular application I was working on using the following steps:

  1. First ensure the bcp executable is installed in the first place. In your Boost root folder, navigate to the tools/bcp folder and run the bjam.exe in here. For me this created the bcp executable in [Boost path]\bin.v2\tools\bcp\msvc-10.0\release\link-static directory:

  2. Then create the folder where you would like the Boost subset to reside. This might already be a folder for a Visual Studio project you are working on.

  3. Run the bcp exectubale you created, making sure to include the libraries you wish to include, as well as the location of the boost root directory and the destination folder. Observe how the required Boost components (eg for regex) have been included in your destination folder.

    bcp.exe regex --boost="C:\Program Files\boost_1_55_0\boost_1_55_0" C:\Projects\RegexProject\BoostLite

  4. In your Visual Studio project set the Additional Include Directories and Libraries to point to the 'Boost lite' folder that was created.

  5. One final thing - which I think is described previously - I needed to go to my regular Boost folder setup and copy the required stage/lib folder containing all the lib files needed for the subset version and copy them here, just a few regex-related lib files in my case.

I found that this worked for me. Any feedback from other persons experiences would be appreciated.

A blog posting describing the same thing can be found here.