How to configure Qt Creator to use Boost in Windows

16,878

I did solve the problem myself. And here is how I did it. First of all, it is required to have boost library compiled with same compiler you're using with Qt.
If you're using msvc, then you're lucky because Boost guys did you a favour and compiled libraries for you. You can download them here: http://sourceforge.net/projects/boost/files/boost-binaries/ .
If you're using mingw (which does come in bundle with Qt), you can do this:

  • add mingw compiler to Windows PATH variable:
    ~ go to control panel and search for System;
    ~ add mingw's path(e.g. C:\Qt\Tools\mingw\bin) to PATH variable by appending ';' to your path(e.g.: ";C:\Qt\Tools\mingw\bin")
  • compile Boost libraries:
    ~ unzip boost archive
    ~ open a Command Line window, go in the unzipped boost folder, then go in folder tools/build/v2/engine
    ~ you have you build installer with mingw toolset: .\build --toolset=mingw
    ~ this will create 2 files in folder bin.ntx86 or something similar; copy the files bjam and b2 in the unzipped boost folder;
    ~ now go in boost folder and start build it: .\b2 --toolset=mingw --build-type=complete stage (there is good tutorial to install it along with eclipse : http://theseekersquill.wordpress.com/2010/08/24/howto-boost-mingw/)
    note: this gonna take few hours, so may want to watch a movie or what ever you want to do meanwhile. However you have the option to speed up things a little bit by adding another argument to the build command: -j N, where N is how many cores your processor have.
  • when build has finished, you can now link the library in Qt. To do this you need to modify .pro file. First you'll have to tell Qt where are headers are located, and you do so by adding:
    INCLUDEPATH += path_to_boost_folder, e.g. : INCLUDEPATH += C:/boost_1_54_0
    ~ also if you're using libraries which requires link, for example system and filesystem you have to link them separately:
    LIBS += "C:/boost_1_54_0/stage/lib/libboost_filesystem-mgw48-1_54.a",
    LIBS += "C:/boost_1_54_0/stage/lib/libboost_system-mgw48-1_54.a"
  • after modifying the .pro file, run qmake, then rebuild.

Hope this works for you too!

Update: The folder hierarchy has change. For building the library, one should read the documentation associated with each version and Boost.Build's documentation. Building the library from the root folder is easier (Building Boost 1.52 with MinGW):

C:\boost_1_60_0> bootstrap.bat mingw  
C:\boost_1_60_0> .\b2 --toolset=gcc -j N --build-type=complete
Share:
16,878

Related videos on Youtube

Athan
Author by

Athan

Updated on September 16, 2022

Comments

  • Athan
    Athan over 1 year

    I created a Qt project in Ubuntu and everything went smoothly. However, I also need deploy it on Windows. It uses Boost libraries(the big problem).

    I've been searching for hours to find a solution, but didn't have luck. I tried to install Boost libraries and link it with mingw; I think I missed something. Here is what I did and downloading the lastest version:

    1) ran .\bootstrap
    2) then .\b2 --prefix=C:\boost install

    Sadly didn't install correctly. I got only 2 folder(bin and share) but no headers.

    However, here (http://nuwen.net/) I found a bundle(Mingw+Boost and other libraries). This has everything I need.

    Now I think the issue is .pro file, because I have a lot of undefined references. Here is .pro file with everything I tried (some commented): http://pastebin.com/pBFMTAd8

    Your help is appreciated!