Simple and efficient C ++ / Boost source distribution (combining)

My work mainly consists of engineering analysis, but I am increasingly distributing the code among my colleagues. The big pain is that not every user has the skills to compile the source code, and I cannot distribute executable files.

I worked with C ++ using Boost, and the problem is that I cannot request every system administrator of each network to install libraries. Instead, I want to distribute one source file (or as little as possible) so that the user can g++ source.c -o program .

So the question is, can you pack the Boost libraries with your code and end up with one file? I am talking about Boost libraries that are just "headers" or "just templates."

As an inspiration, check out the SQlite distribution or Lemon Parser Generator ; the author combines the material into one source file, which is trivially compiled.

Thanks.

Edit

A related question in SO for a Windows environment. I work on Linux.

+7
c ++ boost software-distribution
source share
5 answers

There is a utility that comes with boost called bcp , which can scan your source and extract any boost header files that are used from the boost source. I installed a script that does this extraction in our source tree so that we can package the source that we need along with our code. It will also copy acceleration source files for several supporting libraries that we use, which are not just a header, which are then compiled directly into our applications.

This is done once, and then anyone who uses the code should not even know that it depends on the promotion. Here is what we use. He will also build bjam and bcp if they have not been created yet.

 #!/bin/sh BOOST_SRC=.../boost_1_43_0 DEST_DIR=../src/boost TOOLSET= if ( test `uname` = "Darwin") then TOOLSET="--toolset=darwin" fi # make bcp if necessary if ( ! test -x $BOOST_SRC/dist/bin/bcp ) then if ( test -x $BOOST_SRC/tools/jam/*/bin.*/bjam ) then BJAM=$BOOST_SRC/tools/jam/*/bin.*/bjam else echo "### Building bjam" pushd $BOOST_SRC/tools/jam ./build_dist.sh popd if ( test -x $BOOST_SRC/tools/jam/*/bin.*/bjam ) then BJAM=$BOOST_SRC/tools/jam/*/bin.*/bjam fi fi echo "BJAM: $BJAM" pushd $BOOST_SRC/tools/bcp echo "### Building bcp" echo "$BJAM $TOOLSET" $BJAM $TOOLSET if [ $? == "0" ]; then exit 1; fi popd fi if ( ! test -x $BOOST_SRC/dist/bin/bcp) then echo "### Couldn't find bpc" exit 1; fi mkdir -p $DEST_DIR echo "### Copying boost source" MAKEFILEAM=$DEST_DIR/libs/Makefile.am rm $MAKEFILEAM # Signals # copy source libraries mkdir -p $DEST_DIR/libs/signals/src cp $BOOST_SRC/libs/signals/src/* $DEST_DIR/libs/signals/src/. echo -n "boost_sources += " >> $MAKEFILEAM for f in `ls $DEST_DIR/libs/signals/src | fgrep .cpp`; do echo -n "boost/libs/signals/src/$f " >> $MAKEFILEAM done echo >> $MAKEFILEAM echo "### Extracting boost includes" $BOOST_SRC/dist/bin/bcp --scan --boost=$BOOST_SRC ../src/*/*.[Ch] ../src/boost/libs/*/src/*.cpp ../src/smart_assert/smart_assert/priv/fwd/*.hpp $DEST_DIR if [ $? != "0" ]; then echo "### bcp failed" rm -rf $DEST_DIR exit 1; fi 
+11
source share

Have you just looked at a build script entry for a build system like SCons ?
You can write a python script to load boost, unzip it, compile the necessary files (you can even run bjam if necessary), and compile your own code.
The only dependencies your colleagues will need are Python and SCons.

+3
source share

Run the preprocessor in code and save the output. If you started with one main.cpp with a bunch of inclusions in it, you will get one file into which all incoming messages were pulled. If you have multiple cpp files, you will have to merge them together and then run the preprocessor in the combined file, this should work as long as you don't have duplicate global symbol names.

For a more portable method, do what sqlite does and create your own script to simply merge and merge the files you created + and not include the system. See Mksqlite3c.tcl in sqlite code
http://www2.sqlite.org/src/finfo?name=tool/mksqlite3c.tcl

+1
source share

Why not just check all the necessary files in SVN and send the repository URL to your co-authors? Then they can check the code whenever they want, do svn up anytime they want to upgrade to the latest version, etc.

0
source share

If you are working with a different Debian Linux server, problems like this should not arise: let the packaging system and policy guide do their job. Just make it clear that libboost-dev or any other package is build dependent by your code and should be installed in advance, and then /usr/include/boost should be where your code expects to find it. If you are using a newer version of the upgrade than ships with a distribution, it is probably worth figuring out how to pack it yourself and work within the existing packaging / dependency infrastructure, rather than inventing another one.

I don't know enough about .rpm-based distributions to comment on how they work there. But, knowing that I can easily configure just such a build environment, I need, for me, one of the biggest advantages of Debian-based development over Windows.

0
source share

All Articles