4

I'm writing a small program using boost/program_options to handle options from command line. Now I want to distribute my code to systems where in general Boost is not installed. So I used the bcp utility. I tried it on the example from Boost called example/first.cpp from the program_options tutorial:

bcp --scan --boost=/users2/xxx/boost_1_45_0 ~/prova/first.cpp dest

It create a directory dest with tons of .hpp and .cpp files. I suppose this is what I need and no more. Is is right? Because:

du -hs dest
37M dest

Isn't 37M too much? For example I can do the same thing using Python with test_optparse.py with only 61KB.

Am I doing something wrong? The point is that my source program is only 4MB; I can't add 37MB of third party stuff!!

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141

1 Answers1

3

The Boost.Documentation has more explanations on this topic than I can provide. Most notably :

It should be noted that in practice bcp can produce a rather "fat" list of dependencies, reasons for this include:

[...]

  • When you include a header, bcp doesn't know what compiler you're using, so it follows all possible preprocessor paths. If you're distributing a subset of Boost with you're application then that is what you want to have happen in general.

The last point above can result in a substantial increase in the number of headers found compared to most peoples expectations. For example bcp finds 274 header dependencies for boost/shared_ptr.hpp: by running bcp in report mode we can see why all these headers have been found as dependencies

I suggest you try bcp --report and check the reason for inclusion of each files to see if it really is necessary.

icecrime
  • 74,451
  • 13
  • 99
  • 111
  • ok, this generate an HTML and at the end there is the list of dependencies. But it doesn't help me too much. I can delete files like: `boost/config/compiler/borland.hpp`. Is there an automatic way to keep only the necessary? By the way the point is more general: why I need `any.hpp`, `lexical_cast`, `mpl` and so on, only to parse options from command line? I don't understand. I think I can write a very base option parser using only `` and `` – Ruggero Turra Dec 27 '10 at 15:06
  • @wiso: unfortunately, I think this 'cleaning' will have to be manual... Regarding dependencies, I don't know enough of boost.program_options implementation to give you an explanation, but I presume that if `bcp` yields 274 headers for shared_ptr.hpp only, anything is possible. – icecrime Dec 27 '10 at 15:08
  • 1
    @Wiso, if *all* you want to do is parse options from the command line, then read `argv` and `argc` yourself. But if you want all the neat things that Boost can do, such as have a concise syntax for *specifying* program options, and generating help messages automatically, and storing the values of options in a type-safe manner, then you really do need `any`, `lexical_cast`, and `mpl`, plus all their dependencies. – Rob Kennedy Dec 27 '10 at 17:14
  • 1
    @Wiso, note that the documentation has some advice on getting a set of includes for a single environment: "If you want to figure out which Boost headers are being used by your specific compiler then the best way to find out is to prepocess the code and scan the output for boost header includes." That is, run something like `g++ -E ~/prova/first.cpp | grep '#include.*boost'`. (You can use a fancier grep pattern, or attempt to filter the output somehow, but that should get you started.) Note the warning in the very last sentence of the bcp docs. – Rob Kennedy Dec 27 '10 at 17:20