So here I am, still learning C++ and using the Qt framework. Recently I wanted to know how much disk space is left on a device, so that I can decide if an operation takes place at all.
Surprisingly there is nothing in the regular Qt framework. There seem to be some leftovers in a part of the mobile framework from the Nokia days. But those are not in the distribution that can be downloaded from the Qt project page.
After some research in the forum and our friend Mr. Google I stumbled over the Boost libraries (again - it wasn't for the first time). So I went over to their homepage and hit the
Most parts of the boost libraries are header only, they need no compiling at all. Whut? Yes, they are a bunch of clever templates that do all the work for you. So, download, unzip and there you go (have a look in their getting started guide.
But I wanted something that works with the filesystem and is platform-independent. That's the part where some compiling comes into place. Part of the download was the Boost.Filesystem library. How to compile is described here.
So why is he writing all that stuff here if everything is documented on the Boost homepage? Well, that's kind of a self-therapy. By writing down the steps needed, I can memorize them better and if I need the information in future, I know where to find it. Beyond that it's written in my own language using my wording. Basically the same information but it goes faster into my brain. Last but not least there is the fact that you have understood it for yourself when you can tell others how to do it.
Open you terminal and there you go.
Make a directory where the Boost libraries go and put the downloaded file there
export build=~/devtools # or wherever you'd like to build mkdir -p $build cd $build
I could have put a fancy curl command here but since I wanted that get Boost button in here, I assume that you put the file in there with Finder.
tar -xzf boost_1_53_0.tar.gz
Go into the new boost_1_53_0 directory and for a first glance enter
./bootstrap.sh --help `./bootstrap.sh' prepares Boost for building on a few kinds of systems. Usage: ./bootstrap.sh [OPTION]... Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --with-bjam=BJAM use existing Boost.Jam executable (bjam) [automatically built] --with-toolset=TOOLSET use specific Boost.Build toolset [automatically detected] --show-libraries show the set of libraries that require build and installation steps (i.e., those libraries that can be used with --with-libraries or --without-libraries), then exit --with-libraries=list build only a particular set of libraries, describing using either a comma-separated list of library names or "all" [all] --without-libraries=list build all libraries except the ones listed  --with-icu enable Unicode/ICU support in Regex [automatically detected] --without-icu disable Unicode/ICU support in Regex --with-icu=DIR specify the root of the ICU library installation and enable Unicode/ICU support in Regex [automatically detected] --with-python=PYTHON specify the Python executable [python] --with-python-root=DIR specify the root of the Python installation [automatically detected] --with-python-version=X.Y specify the Python version as X.Y [automatically detected] Installation directories: --prefix=PREFIX install Boost into the given PREFIX [/usr/local] --exec-prefix=EPREFIX install Boost binaries into the given EPREFIX [PREFIX] More precise control over installation directories: --libdir=DIR install libraries here [EPREFIX/lib] --includedir=DIR install headers here [PREFIX/include]
Ok, the option --show-libraries will tell us, what is in stock here.
./bootstrap.sh --show-libraries -n Building Boost.Build engine with toolset darwin... tools/build/v2/engine/bin.macosxx86_64/b2 The following Boost libraries have portions that require a separate build and installation step. Any library not listed here can be used by including the headers only. The Boost libraries requiring separate building and installation are: - atomic - chrono - context - date_time - exception - filesystem - graph - graph_parallel - iostreams - locale - math - mpi - program_options - python - random - regex - serialization - signals - system - test - thread - timer - wave
OK, we wanted something for the filesystem and surprise, surprise: it's called filesystem.
The option --with-libraries tells that bootstrap script which library to build (if not all and I just want that file thingy). On top of that we can use --prefix to tell where the build library goes in our filesystem. Long story short:
./bootstrap.sh --prefix=$build/boost_1_53_0/filesystem --with-libraries=filesystem -n Building Boost.Build engine with toolset darwin... tools/build/v2/engine/bin.macosxx86_64/b2 -n Unicode/ICU support for Boost.Regex?... not found. Generating Boost.Build configuration in project-config.jam... Bootstrapping is done. To build, run: ./b2 To adjust configuration, edit 'project-config.jam'. Further information: - Command line help: ./b2 --help - Getting started guide: http://www.boost.org/more/getting_started/unix-variants.html - Boost.Build documentation: http://www.boost.org/boost-build2/doc/html/index.html
We will se if the "Unicode/ICU support for Boost.Regex?... not found." message means anything. Enter
./b2 Building the Boost C++ Libraries. Component configuration: - atomic : not building - chrono : not building - context : not building - date_time : not building - exception : not building - filesystem : building - graph : not building - graph_parallel : not building - iostreams : not building - locale : not building - math : not building - mpi : not building - program_options : not building - python : not building - random : not building - regex : not building - serialization : not building - signals : not building - system : not building - test : not building - thread : not building - timer : not building - wave : not building ...patience... ...found 507 targets... ...updating 46 targets... common.mkdir stage common.mkdir stage/lib common.mkdir bin.v2 common.mkdir bin.v2/libs common.mkdir bin.v2/libs/system common.mkdir bin.v2/libs/system/build common.mkdir bin.v2/libs/system/build/darwin-4.2.1 common.mkdir bin.v2/libs/system/build/darwin-4.2.1/release common.mkdir bin.v2/libs/system/build/darwin-4.2.1/release/threading-multi darwin.compile.c++ bin.v2/libs/system/build/darwin-4.2.1/release/threading-multi/error_code.o darwin.link.dll bin.v2/libs/system/build/darwin-4.2.1/release/threading-multi/libboost_system.dylib common.copy stage/lib/libboost_system.dylib common.mkdir bin.v2/libs/filesystem common.mkdir bin.v2/libs/filesystem/build common.mkdir bin.v2/libs/filesystem/build/darwin-4.2.1 common.mkdir bin.v2/libs/filesystem/build/darwin-4.2.1/release common.mkdir bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/codecvt_error_category.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/operations.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/path.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/path_traits.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/portability.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/unique_path.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/utf8_codecvt_facet.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/windows_file_codecvt.o darwin.link.dll bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/libboost_filesystem.dylib common.copy stage/lib/libboost_filesystem.dylib common.mkdir bin.v2/libs/system/build/darwin-4.2.1/release/link-static common.mkdir bin.v2/libs/system/build/darwin-4.2.1/release/link-static/threading-multi darwin.compile.c++ bin.v2/libs/system/build/darwin-4.2.1/release/link-static/threading-multi/error_code.o darwin.archive bin.v2/libs/system/build/darwin-4.2.1/release/link-static/threading-multi/libboost_system.a common.copy stage/lib/libboost_system.a common.mkdir bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static common.mkdir bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/codecvt_error_category.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/operations.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/path.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/path_traits.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/portability.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/unique_path.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/utf8_codecvt_facet.o darwin.compile.c++ bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/windows_file_codecvt.o darwin.archive bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/libboost_filesystem.a /usr/bin/libtool: file: bin.v2/libs/filesystem/build/darwin-4.2.1/release/link-static/threading-multi/windows_file_codecvt.o has no symbols common.copy stage/lib/libboost_filesystem.a ...updated 46 targets... The Boost C++ Libraries were successfully built! The following directory should be added to compiler include paths: /Users/sven/devtools/boost_1_53_0 The following directory should be added to linker library paths: /Users/sven/devtools/boost_1_53_0/stage/lib
Yes, there you go: it reads The Boost C++ Libraries were successfully built! :-) And there is also the most important hint:
The following directory should be added to linker library paths: /Users/sven/devtools/boost_1_53_0/stage/lib
That is nice! I like it when toolsets are that easy to build and use. One step left. I want to use it with Qt/QtCreator, so add that information to the .PRO file
LIBS += /Users/sven/devtools/boost_1_53_0/stage/lib -lboost_filesystem -lboost_system INCLUDEPATH += /Users/sven/devtools/boost_1_53_0
One could think that
LIBS += /Users/sven/devtools/boost_1_53_0/stage/lib INCLUDEPATH += /Users/sven/devtools/boost_1_53_0
is enough, but the compiler complains here (hey, I am still a C++ novice).
Of course you should use your own path here. That was easy and fast. What are you waiting for? Do it for yourself.