Why does read_graphviz in BGL need to be compiled? - boost-graph

I like boost because most things don't need to be compiled, only included. The vast majority of the BGL is not compiled but the read_graphviz functionality needs to be built. It seems like most of the other compiled libraries in Boost need more information about your hardware. Why would read_graphvis need to be compiled on the machine? Parsing a graph format seems like something that could easily be tackled in a header only include file similar to the rest of BGL.

Related

Strategy to omit unused boost src files while shipping source code

I'm using
#include <boost/numeric/ublas/matrix.hpp>
in fact that's the only boost file I've included. Now I want to ship the source code and I was hoping not have to include all hundreds of MBs of boost_1_67_0.
How to deal with this issue?
This is simply something you would add to the list of build-dependencies of your C++ source code.
This kind of dependency could be made technically "bound" to your source code distribution via your version control system. In Git, for example, you could link to certain Boost libraries via a sub-module that links to their official git mirrors (github.com/boostorg as of this writing). When cloning your repository, it would then be an option to take in the Boost libraries at the same time.
Though, taking the size of the Boost headers into consideration, having them installed as a system-wide library, might be less complicated. Tools like CMake can help you write the logic for header-inclusion so you can support different header locations.
Of course, if what you seek is to create a fully isolated copy of your source code, the approach to bake all code into one massive header-file might be an option as well (but it should not be necessary).
You can preprocess the one header file you need, which will expand all its #includes:
c++ -E /usr/include/boost/numeric/ublas/matrix.hpp -o boost_numeric_ublas_matrix.hpp
Be aware though: this will expand even your system header files, so it assumes your users will build on the same platform. If they might compile on different platforms, you should simply omit the Boost code from your project and let the users install it themselves in whatever manner they choose.

How can you find out which .dylib file contains a certain boost functionality

I am using Boost in an Xcode and have to add the .dylib files that contain the functionality that is used. Some of them makes perfect sense from the naming e.g. libboost_signals.dylib for using signals. But i can't find the .dylib to include for stuff like mpl and Boost.type_traits. I have searched the web but it didn't give me anything. Could somebody point me in the right direction?
Some of boost libraries are header only. That means that they consist only of header files, so they have no dylib's (so's on linux and dll's on windows). If you deal with templates you can't compile them beforehand: you have to provide source code which will be instantiated with proper types and compiled in-to a object file which uses them.
mpl and type_traits are header only so you don't need to add any additional dylib's to your project.
You can explore symbols inside libraries using nm, for example, try running nm libboost_signals.dylib

How to use a library in a single file C++ code?

How can I use a library such as the GMP library in C++ in such a manner that the file can be compiled normally without having the person compiling to install the GMP themselves. This is for personal use(so no license issues etc.). I just want my client to be able to compile my C++ code which needs the GMP library. I tried using g++ -E option, and it kinda works, but the problem is that on top of it are included many files which are themselves part of the library(and not available without the lbrary). Also the linker needs the availability of the library even if I do do that successfully.
How do I copy the entire library per se, maintaining a single file of code, such that it compiles and doesn't cause problems. I'm quite sure it is doable, because copying some functions works like a charm, but I can't copy paste the 3000 line code manually, so how to do it?
If I understand you correctly, I guess what you want is to have your source and the entire GMP library in one file? And you want to do that automated?
I think there is no standard way to do this. You could write a script in you favorite language (bash, python, etc) which traverses the GMP code tree, appending the files (first the header files, then the cpp files) to your file while ignoring all local #include-lines. And hope that there are not too many macros etc which rely on the folder structure to be intact.
However, you could (and probably should) just supply the library and a adequate Makefile with your source code. Then the client wouldn't need to install the GMP lib, but could unpack the archive and run make. If the constraint is to do this in one file, maybe it is wiser to change that constraint...

Is it possible to read code of a C++ library and modify it?

A bit of a simple question, though the answer may not be. I am fairly new to C++ and was wondering if it was possible to open a C++ library and see it's code. It sounds like a potentially risky move to accidentally change the core code of the library, but I would still like to see if it is possible. Thank you!
There are too kinds of libraries that C++ can use:
compiled to binary libraries which are linked with linker to your
executable;
headers-only libraries which are just included with include into
your source code
You can "open" headers of headers-only libraries and modify code if you wish (but not recommended).
Also many compiled libraries are open source. You can open source files there. If you want to modify such library, you will need to compile it and link your executable against this modified version.
Yes it s possible to open a c++ library and see its code.
If you want to make changes to any functionality simply create your own version of it giving it a different name, or if you want to add functionality just simply extend the class you are interested in. (read up on inheritance for this).

Tool to create an amalgamation/combine all source files of a library into one for C/C++?

SQLite and googletest come with a very easy-to-use, single-file version which makes it a breeze to use it in other projects, as you just need to add a single source file. Both of them use home-brew tools to create the combined source file, so I wonder if there is a more generic tool for this? It should take a list of implementation/header files and spit out a combined header/source, and fix up the local includes. I'm fine if it doesn't handle conditional includes/includes with different #defines before them like Boost.Tuple/MPL uses them. A typical target library would be something like ICU.
try this
https://github.com/vinniefalco/Amalgamate/
may be it can help...
If your includes are correctly defined (that is, there are guards in all header files, and each header/code unit contains all includes that it requires) then you can do it 'half-manually'. Locate system header includes and comment them out, then create a header that just includes everything in any random order and preprocess the header (in gcc that would be gcc -E) and then operate similarly with the code units.
This manual approach can be cumbersome, but if you only need to do it once it will be fine. Then again, even if merging the header files might make sense I prefer not to do it. I would actually leave the files separate, and if you feel like you need to simplify access to it, provide bundling headers that just include the others. This is the approach that some boost libraries take, where you can include the details of what you want or a single header that includes everything else. The code can be compiled/linked into an static lib and used as if it was a single element.
This might be sort of interesting in ICU, which has, in some cases, incompatible defines/includes and mixtures of C and C++ and a number of generated files. Maybe let us know how it goes?
(disclosure: icu developer)