Extracting small parts of large library (fx boost)
I would like to know if there is an automated way to extract a small portion of a large C++ library.
Let's say I only need boost::rational in some project. However entire boost 1.42 takes up 279 开发者_如何学运维MiB!
To keep my project "self-contained" (fx for some school work), I would like to be able to include boost::rational along with my own source. (The idea being, that my teacher should not have to install 1000's of libraries in advance in order to compile)
I know this violates good practice, as it would be better to actually have entire boost installed - but the argument nevertheless holds with other (lesser know) large libraries.
I guess this extraction could be done easily by walking the #include dependency tree of the root #include (like boost/rational.hpp); but has such a tool been made? What's its name?
Under Linux you can use the "x" flag to "ar" to extract all the object files from a library.
You can use "nm" to determine what symbols are needed by your code, and which (library) object files define them. (There is an optional --demangle flag, which might help human's reading the output.)
You could then build a new library consisting of just the object files you needed. (Via "ar" and "ranlib".) Or just compile (link) them in directly on the command line.
It's a simple matter of scripting to find the symbols missing from your (compiled) object code, and then which object files from the library define them. And then of course what symbols are missing from those library object files that require other library files... And the ones that are missing from these new library (object) files... And so on. And so on.
It boils down to a lot of work for (usually) far too little gain. Especially when you get into things like Weak Symbols, Indirect References, etc.
精彩评论