简体   繁体   中英

Configure Qt Creator to use Boost on Windows

I want to use boost with C++ in Qt Creator on Windows. I followed the instructions from:

http://www.boost.org/doc/libs/1_51_0/doc/html/bbv2/installation.html

So I ran .\\bootstrap.bat then ./b2 install --prefix=C:\\Boost then I added C:\\Boost\\bin to your PATH environment variable.

I want to make Qt Creator "see" boost now and I couldn't find any resources on the web. Can someone give me a hint please?

Well I finally managed to compile a couple of the Boost Filesystem examples found at Boost Filesystem tutorial with in Windows 7 with Qt Creator 2.7.1, Qt 4.8.4 and Boost 1.54. Here is my qmake project file.

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

win32 {
    INCLUDEPATH += C:/boost/include/boost-1_54
    LIBS += -LC:/boost/lib \
            -lboost_serialization-mgw46-mt-d-1_54 \
            -lboost_filesystem-mgw46-mt-d-1_54 \
            -lboost_system-mgw46-mt-d-1_54
}

Please note the usage of "/" instead of "\\".

My Boost library was compiled to the "c:\\boost" directory using MinGW.

I will answer this question based on other answers I found.

First, you need to use boost libraries compiled with the same compiler used by QtCreator (usually mingw). If you use prebuilt boost libraries (usually compiled using msvc), libraries will link but undefined reference error will occur.

So, you need to compile boost libraries by yourself. To do this, follow these steps:

  1. Add the mingw binaries to PATH. Go to Control panel > System > Advanced settings > Environmet variables and set the path variable. In my case, the value was c:\\Qt\\Tools\\mingw\\bin .

  2. Open a terminal and go to the directory in which boost was decompressed. Run this: bootstrap.bat gcc

  3. Now run this: b2 link=shared toolset=gcc

I think you've got yourself confused a little bit.

The link you've mentioned is for the Boost Build system, not for the Boost libraries. There's a full installer on www.boostpro.com for the library files, that'll get you up and running a bit faster, however if that's not working properly there's a guide here on building it yourself.

Next step after you've got them built is to make Qt aware of them. You generally do this on a per project basis, either by adjusting the settings through Qt Creator or by directly editing the .pro file for your project. I prefer editing the .pro as it's how I learnt, if you go down that route you need to let it know the INCLUDEPATH for the header files and the LIBS path for the libraries. A lot of Boost is header file only, so depending what parts you use you may or may not need the LIBS part.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM