Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract boost::filesystem using bcp

Tags:

c++

boost

bcp

I'm trying to create a subset of the boost library including the filesystem module, so I can include that subset in my project repository. I got a linker error until I copied the .lib files over manually. I'm using Visual Studio 2013 on Windows 7 64-bit.

I've successfully extracted boost/algorithm/string.hpp and its dependencies using bcp, by using the following steps:

  1. Downloaded (v 1.57.0) from boost.org.

  2. Extracted.

  3. Ran

    bootstrap.bat
    

    then

    b2.exe
    

    as described at Getting Started on Windows.

    (I don't know if b2 was necessary for my purposes.)

  4. Built the bcp tool by opening a command prompt where I had extracted the boost archive, and ran

    bjam tools\bcp
    

    as described here.

  5. Created the boost library subset by running

    dist\bin\bcp.exe algorithm/string.hpp [outdir]
    
  6. Copied the result into a subfolder under my project, added the boost directory to the C++ include search path, and built the project.

...

When I add filesystem or filesystem.hpp to the command above, (even if I use the --scan option on my own source file(s),) and copy the result to my project folder, then just try to include "boost/filesystem.hpp", I get

LINK : fatal error LNK1104: cannot open file 'libboost_system-vc120-mt-gd-1_57.lib'

There were no *.lib files to be found in the output from bcp. To get it to build, I had to manually copy the libboost_system-*.lib and libboost_filesystem-*.lib files from stage\lib\ to my project (and add the directory containing them to Project Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories).

Is this expected behavior that bcp didn't copy everything needed? Or did I miss a step? Or is it a bcp bug?

like image 515
cp.engr Avatar asked Jan 28 '15 00:01

cp.engr


2 Answers

Short answer

bcp will only copy source files, so you will have to build the libraries again from the source tree that bcp generates. So yes, this is expected behavior and yes, you missed a step. :)

I don't think it is a bug in bcp itself, but the process of generating a Boost subset is certainly not particularly user-friendly. See below.

Long answer

If you get dependencies that need compilation (e.g. boost/system), you also need to include the stuff needed to be able to build in the new source tree. The dependencies seem to change between Boost versions, but by trial and error I have found out that for 1.57 you need to add build, bootstrap.bat, bootstrap.sh, boostcpp.jam and boost-build.jam to the bcp command, so that you can do a build from the new source tree:

dist\bin\bcp.exe algorithm/string.hpp build bootstrap.bat bootstrap.sh boostcpp.jam boost-build.jam [outdir]

Edit: Depending on Boost version, you may also need to add config to the above line to prevent build errors (suggested by Sebastian Marsching). -- End edit

Then, and this does feel like a bug in the build scripts, you have to open the top-level Jamfile in your newly generated tree and comment out or remove the two use-project lines that mention /boost/tools/inspect and /boost/libs/wave/tool. Otherwise the failure to find these directories will break the build. Another option, of course, is to include tools/inspect and wave on the bcp command line, but they bring with them quite a lot of dependencies, so I wouldn't recommend that unless you want these particular tools/libraries.

Then you need to add a build step to your own project to build the libraries, using the same procedure as you used to build the full Boost package (i.e. your step 3, but inside your "minified" source tree).

If you want, you can add the already-built b2 and bjam binaries to your source tree instead of the bootstrap step, but then you will only be able to build on platforms where those binaries can run.

And by the way, the "b2" part of your third step is indeed not necessary.

like image 140
Emil Styrke Avatar answered Sep 21 '22 23:09

Emil Styrke


I forked bcp on GitHub, and compiled out a binary bcp, then I used this binary bcp to extract out all necessary header files sources files of bcp from BOOST library. Then I packed a standalone bcp distribution. (You can easily compile the code and get a dependency free bcp file on Windows or Linux. I offered several download links on my fork.)

This process may help you, Check out here for detail. I came across link problems too, see Boost auto_link is the cause of build failure on Windows, just comment out this header file will be fine.

The link problem on Windows MSVC is due to Boost's autolink behavior. Checkout boost/config/auto_link.hpp for further infomation.

like image 31
Dvorak4tzx Avatar answered Sep 22 '22 23:09

Dvorak4tzx