Как подключить Boost к Qt Creator?
Нужно подключить библиотеку boost/asio к проекту (чистое консольное с++ приложение для практики) в qt creator.
Скачал исходники с сайта. Прочитал что asio не надо билдить и все находится в хидерах.
В гугле прочитал что достаточно добавить директорию в INCLUDEPATH += .
Добавил INCLUDEPATH += C:/WORK/boost_1_59_0 .
После этого в редакторе работает автодополнение в #include «boost/asio.hpp» .
Но при сборке выдает
Запустил qmake — стало выводить
Это в одном из хидеров подключается другой хидер который он не может найти.
Подключил правильный комплект сборки.
Стало выдавать
- Вопрос задан более трёх лет назад
- 8143 просмотра
- Вконтакте
В общем все решилось тем что надо было правильно записать все в файл проекта (*.pro) и нажать qmake.
При этом хоть изначальная библиотека (asio) основана только на header`ах и имплементациях, но использует другие библиотеки Boost и соответственно подключает/включает их при подключении соответствующего .hpp .
То есть необходимо было собрать предварительно весь буст своим компилятором в либы, либо скачать уже готовые под винду с офф сайта .
В итоге в файл .pro добавляется
жмется qmake и дальше все собирается.
ПС: получилось что сам спросил — сам ответил.
но надеюсь зато в следующий раз кто-то быстро найдет в поисковике проблему и увидит решение.
Introduction
exist Qt Sometimes you need to use in the project boost Library. The ready-made not necessarily available online can be used, so I understand the compilation method.
Target
learn FPGA The origin and characteristics.
Reading foundation
Familiar with the computer.
Speed Reading
The part of the understanding is skipped.
Environmental note
Reference
QT5.12.6 compiler preparation
download
Install
According to the guide installation, pay attention to check mingw730_32 and mingw730_64 translater.
Configure
Finish QT After it comes with mingw730_32 Compiler directory. As shown below:
Add this directory to system environment variables path In the following:
verify
Open Qt5.12.6(MinGW 7.3.0 32-bit . As shown below:
After clicking, enter the command line interface, as shown below:
input the command gcc -v The test is successful. As shown below:
Boost library download
ClickOfficial download addressEnter Boost Official website — "Click on the version you want to download. As shown below:
Download the decompression. As shown below:
Enter boost_1_78_0 content. As shown below:
Compilation of the Boost library
Open MINGW
Best qt Own minGW The compiler, I opened here is Qt5.12.6(MinGW 7.3.0 32-bit . As shown below:
After clicking, enter the command line interface, as shown below:
Generate compilation tools
Enter boost Unzip the root directory CD / D BOOST decompression path ,Mine is G:\boost\boost_1_78_0
Execute in the current directory bootstrap gcc ,As shown below:
Willing boost Root directory generation b2.exe 、 project-config.jam 、 bootstrap.log Three files
at the same time boost Unzipped boost_1_78_0\tools\build\src\engine Two exe document b2.exe , bjam.exe ,As shown below:
Compilation installation
Compile and install boost Enter the following command, the default is installed to the C drive.
- stage Represents only the library ( dll and lib ), install It also generates a header file include content;
- —build-type=complete Mend Debug and Release Version;
- threading=multi Indicates the use of threading multi (Multithreading);
- link=shared Represents link mode shared (Ie, building a dynamic library), static Indicates compiled into a static library;
- address-model=64 Indicates the address model 64 Bit (ie the generated library is 64 Bit library;
- toolset=gcc Indicates tool set gcc ;
- —prefix = "Specify Output Directory Path" ,like —prefix="D:\soft\boost"
- —BUILD-DIR = "Specify Output Directory Path Build" like D:\soft\boost_1_70_0\build
The execution process is as follows:
The installation is complete
After the installation is completed C Generate one in the root directory Boost folder. As shown below;
There are four static library files. As shown below:
BOOST library to QT project
Boost library is in the project
Copy Boost library
Complete and store it before C Underwent Boost Copy to the project directory.
Add compilation options in the PRO file
- DependPath + = Boost library 2 credit file path
- INCLUDEPATH + = BOOST library head file path
- Libs + = -L
<-l + Boost Library 1>
Boost library is stored under QTCREATOR
Copy Boost library
Generated Boost/include/boost-1_xx add to qt Creator of include Below, as shown below:
Name already in use
qt-creator-plugin-boostbuild / README.md
- Go to file T
- Go to line L
- Copy path
- Copy permalink
- Open with Desktop
- View raw
- Copy raw contents Copy raw contents
Copy raw contents
Copy raw contents
Boost.Build Plugin for Qt Creator
The Boost.Build (long name: Boost.Build Project Manager) plugin provides basic Boost.Build support for Qt Creator.
The idea of the Boost.Build plugin is extremely simple — use Qt Creator as a basic GUI shell to interact with the Boost.Build command.
Three main features:
- Open Boost.Build Jamfile as a project in Qt Creator.
- Build project in Qt Creator according to its configuration in Jamfile.
- Parse Boost.Build command output to enable navigation to error or warning locations.
Think of the plugin as an equivalent of Vim or Emacs with ctags and bunch of other scripts.
It turns out, that in order to achieve the three basic features above, a project manager plugin for Qt Creator needs to implement a few beefy features like: opening a project, reading project directory structure, creating nodes of project explorer tree, creating build, run, deploy configurations and corresponding build, run, deploy steps and more.
So, the Boost.Build plugin implements as little as necessary, and currently, it does not provide:
- any parsing capabilities for Boost.Build Jamfiles (not entirely true, see Features)
- any kind of GUI for updating or managing configuration stored in Jamfiles
- Tobias Hunger, Koehne Kai, Christian Kandeler, Nikolai Kosjar, André Pönitz and others for great help on the qt-creator mailing list and IRC, for writing the Building Qt Creator from Git and support through qt-creator list, for answering questions about Boost.Build,
- Authors of existing project manager plugins for Qt Creator — prime learning resource,
lots of thanks to!
What the Boost.Build plugin can do?
- Select a Jamfile at any level of a source tree configured with Boost.Build.
- Select files at any level of a source tree and register them as project files.
- Open Jamfile pretending it is a Qt Creator project file.
- Parse selected Jamfile to retrieve project name, if defined. Otherwise, Jamfile parent directory name is used as a project name. Finally, project name can be freely changed.
- Generate list of include paths based on configured project files tree.
- Utilise C++ browsing and editing capabilities and features of Qt Creator.
- Including the fantastic searching with the Locator
- Currently, GCC and Clang parsers are provided.
What the Boost.Build plugin can not do?
- Create new projects based on Boost.Build (simply, create Jamfile manually).
- Parse Jamfiles to collect list of source files which are actually used.
- Parse Jamfiles to collect configuration of targets, attributes, requirements, etc.
- Capture any project changes made in Qt Creator UI and automatically update Jamfiles.
- Change any Boost.Build configuration.
- .
You need to build the plugin from sources.
Generally, follow the Getting and Building Qt Creator section from the Creating Plugins guide.
I use Qt and Qt Creator built from sources in their Git repositories, for example:
- Qt 5 from branch: stable
- Qt Creator from branch: 3.3
So, I recommend to follow these guides:
Once you have Qt Creator build ready, you need to set two environment variables:
- QTC_SOURCE — Qt Creator sources location (e.g. path to Git clone)
- QTC_BUILD — Qt Creator build or install prefix where the plugin will be deployed
You can either set the variables in CLI console, if you’re going to run qmake directly or in Qt Creator, in Build Environment settings of the boostbuildprojectmanager.pro project, after you open it in the IDE in order to build the plugin from Qt Creator.
- Go to Open Project and navigate to Jamfile of your project.
- Open Boost.Build Project wizard opens
- First page Project Name and Paths allows to inspect several paths and customise Project name.
- Second page Files Selection allows to generate list of files to attach to the project node in Qt Creator Projects tree and to use as input for C++ model to enable C++ navigation features for the project.
- Third page Project Management allows to add the project as a subproject, enable version control system and displays summary of auxiliary files generated by the wizard.
- Finish the wizard and let Qt Creator to generate the project tree and parse all the source files attached generating C++ model of the code.
- Go to Projects mode to inspect and customise variety of settings:
- b2 command working directory, that is where the command is executed
- build directory given to b2 as value of —build-dir option
- build steps and arguments for b2 command (e.g. change toolset, build variant)
- add custom build steps
- create run configuration with executable targets for testing and debugging
- Also, you can edit .qtcreator.files to add or remove source files and edit .qtcreator.includes to specify include paths if C++ model is missing any.
For more details about individual features, steps and settings check the FAQ.
Why Boost.Build plugin for Qt Creator?
I always wanted to learn Qt programming.
When my son Hugo was born, I went on two weeks paternity leave and, somewhat inspired by the Seven by Seven idea, I decided to do an experiment: can I learn a new programming skills or work on an open source project having only a few 15-30 minutes short breaks over a day at my disposal?
Qt Creator is a fantastic and powerful IDE which is surprisingly easy and pleasent to extend.
Yet, apparently, it is much quicker to hack fairly usable Boost.Build support for Qt Creator than develop Boost.CMake and wait until it is approved by the Boost project.
Is it part of Qt Creator?
Will it become part of Qt Creator?
No demand, no man power, no plans.
UPDATE: There was an attempt to prepare contribution of this plug-in for to Qt Creator, but it failed. See the Issue #13 for details.
How does it compare to Generic Project plugin?
The Boost.Build plugin is inspired and largely based on the Generic Project plugin (aka GenericProjectManager), both idea and implementation.
The Boost.Build plugin is a hybrid between «Open Project» and «Import Project» plugin.
Similarly to Generic Project support, the Boost.Build plugin:
- allows to use Qt Creator as a code editor,
- generates .files and .includes kinds of auxiliary files
- allows to control some of aspects of the way project is built by modifying the build command in the Projects mode under Build Settings
- needs to be told which executable to run in in the Projects mode under Run Settings, because Qt Creator cannot automatically determine it (see TODO items)
Unlike Generic Project support, the Boost.Build plugin:
- can only use Boost.Build system and its b2 command,
- relies on build configuration existing in project Jamfile files
- relies on Boost.Build project hierarchy set up by Jamroot and Jamfile files.
- allows to specify b2 working directory which can be different from both, build directory and project directory, where project directory means directory with Jamfile selected to open as a project.
- allows, thanks to previous features, to open only sub-project of a large project, for example, while working with Boost, one may use the Boost.Build plugin to compose a project which loads files only for selection of libraries, but request to run build against the whole Boost C++ libraries collection.
Finally, the Boost.Build plugin is a pilot project integrating Boost.Build system with an IDE and this experience may be useful for future improvements and development of Boost.Build system itself.
What version of Qt Creator is supported?
I use Qt Creator 3.3, but it should work with Qt Creator 3.0 or later. There are git tags corresponding to Qt Creator versions.
See also the Installation section.
How to install the plugin?
Do I need to build Qt?
I don’t know. Ask Qt folks.
Qt Creator requires private headers of Qt, which are unfortunately not installed by the Qt binary packages
Do I need to build Qt Creator?
It is also necessary if you want to create your own Qt Creator plugin.
Have you used it on Windows?
Have you used it on Mac OS X?
Jamfile is a makefile of Boost.Build written in dedicated Boost.Jam language and interpreted by Boost.Build engine which is executed and controlled by Boost.Build command b2 . See Boost.Build Overview for more details.
Boost.Build convention is that the top of project hierarchy is called project root where lives a Jamfile called Jamroot . A project may define subprojects and each subproject is defined by a Jamfile called Jamfile in a descendant directory of the project root.
For both, root and subproject Jamfiles, Boost.Build recognises variety of file names:
- [Jj]amroot as well as [Jj]amroot.jam and project-root.jam
- [Jj]amfile as well as [Jj]amfile.jam , [Jj]amfile.v2″ and [Bb]uild.jam«`.
Most of those names are recognised by the Boost.Build Project Manager plugin.
What is *.qtcreator.files file for?
Qt Creator, the Boost.Build plugin, for a Jamfile which is opened as a project, automatically generates .qtcreator.files file with list of all files selected in the Files Selection page of the project wizard.
Role of this file is exactly the same as role of .files file for the Generic Project. It just uses different extension to clearly indicate its role and avoid file name clashes.
To add or remove files, edit the .qtcreator.files file in Qt Creator. (TODO: Qt Creator recreates your project tree when you save the .files file.)
What is *.qtcreator.includes file for?
Qt Creator, the Boost.Build plugin, for a Jamfile which is opened as a project, automatically generates .qtcreator.includes file.
This file is dedicated to specify any include paths which are solely used by Qt Creator for analysing C/C++ code of the project. Note, these include paths do not affect compilation of source files whatsoever as Jamfile files remain the only source of build configuration.
The project wizard generates initial list of include paths adding every directory of project which contains C/C++ header files. For large projects, like Boost, this may generate long list of includes paths, though it should be easy to filter it.
To add or remove include paths, edit the .qtcreator.includes file in Qt Creator. The paths can be either absolute or relative to the .qtcreator.includes file.
What is *.user file for?
This file is natively created by Qt Creator when Opening Projects:
Qt Creator stores information that it needs to build projects in a .user file.
The Boost.Build Project Manager also uses this file to store information specific to corresponding Jamfile project, like:
- name of Jamfile project which can be customised by user in the Open Project wizard
- path of working directory used to run Boost.Build command b2
- path of build directory passed as value of b2 option —build-dir
What is the Project Name in the Open Project wizard used for?
The Open Boost.Build Project wizard suggests project name on its first page titled Project Name and Paths.
The wizard tries to extract project name from the Boost.Build project rule, if present in the Jamfile being opened. Otherwise, the wizard uses name of parent directory of the Jamfile. Finally, user can change the Project name freely as it is only used by Qt Creator, not by Boost.Build configuration.
The idea is to provide certain degree of freedom in arranging Jamfile-based projects in Qt Creator session, regardless of their arrangements on disk.
This feature, for example, allows to generate and open multiple projects into Qt Creator and all projects may refer to the same Boost library. For instance, working with Boost.Geometry library, one may load Jamfile for tests and Jamfile for examples, selecting the same set of headers in both, and name the projects to reflect their purpose.
What is the roadmap?
None, apart form plan to roll the project forward fixing bugs and adding features as they appear useful or necessary in order to make work with Boost.Build-based a bit more accessible and efficient.
See Future section for some feature ideas.
How can I contribute?
Fork the repo and make the plugin better!
An unprioritised TODO list for the plugin:
- Add tests! Add tests! Add tests! But first, learn how to test with Qt wealth!
- Add file watchers for Jamfile and sidecar files to automatically reload any changes.
- Qt Creator recreates your project tree when you save the .files file.
- See TODO item about user-config.jam lookup.
- Collect and resolve include paths as specified in all Jamfiles in project tree.
- Collect preprocessor defines from all project Jamfiles.
- Default toolset and use it for Kit selection/validation? See separate TODO item.
- use b2 for reporting include paths for a project, targets, preprocessor defines and build configuration settings.
- extracting parser from tools/build/v2/engine as reusable library
- making some love with Boost.Spirit
See also opened enhancement issues at GitHub or search through the sources for TODO , there is more items.
LiveAndLearn
This tutorial will show you how to create a CMake project that associated with Boost and QT library. For better understanding, please download my completed tutorial project from Download Complete Project
The source project use Qwidget, Qml, boost Signal2 and boost thread. It also contains .UI and .RCC file. The app will be built on Windows and Kubuntu Linux (the KDE version of Ubuntu) using MSVC and GCC.Background
C++ is available on many platforms. So are the QT and Boost library. Unlike C#, C++ compiler generates the native binary file which cannot be run on other OS. Therefore, C++ source code has to be complied on certain compiler/OS in order to create a valid application. This is seemed to be an overhead, but the performance of native application is worth the trouble. See this article.
CMake
CMake is a free opensource tool for managing the build system. CMake will read your project infomation from CMakeList.txt and then, generate native build project file (ie. .sln , MakeFile).
QT is a GUI and aplication framework. QT has their own specific compiling steps. Fortunately, CMake already has a feature to handle that. Such features are AUTO_MOC, AUTO_UIC and AUTO_RCC.
Boost
A programing language without framework is powerless. The standard C++11 library is still small compare to other frameworks such as .NET. Thus, we need Boost library which contains almost everything you need for general work.
Installing CMake, Boost and QT
Installing CMake
Obtains the CMake installer from CMake download link . Then, run the installer wizard.
For Kubuntu Linux, modify the file permissions and run with these commands.
Installing QT
Obtains the QT installer from QT download link .
On that page, I personally prefer choosing the offline installer. Click the “view all download“ link to show the offline installers.Make sure that you have downloaded the correct version and architecture of complier. For example, if you plan to build Boost by visual C++ 2013 32 bit, choose Qt 5.4.1 for Windows 32-bit (VS 2013, OpenGL, 695 MB). For the install location, please read «Managing Source Code and Build Information».
For Kubuntu Linux, modify the file permissions and run the .run file.
Installing Boost
-
Run bootstrap.bat (bootstrap.sh for Linux)
toolset=msvc-12.0 Use the visual C++ 12.0 2013 complier (For Linux, use toolset=gcc-4.8). link=static Build as static lib. Address-model=32 Set binarie’s architecture to 32 bit. Use Address-model=64 for 64 bit. Install This argument will copy the output file to the prefix folder. —build-type=complete Build both debug and release version. —build-dir=C:\Boost\Build Directory for object files and caches (just an intermediate files). —prefix=C:\Boost The location of “output” library. In this tutorial, I will use —prefix=C:\Boost64 for 64 bit build. For Linux, I will set prefix to —prefix=/home/apivan/boost.To customize this please see my CMakeList.txt. Please notice the difference between double dash “—” and no dash. You possibly have some built failure on python-related libs. You can simply ignore it, or just installs python.
For Kubuntu Linux, make sure that you have OpenGL installed.
Managing Source Code and Build Information
All the source code will be located here in the source directory. In other word, only files in this directory should be pushed into your version control.You can skip this session if you only interested in building the tutorial project.
Below are the files in this tutorial project.
Let observe the CMakeList.txt file.
As you can see, the code is very straight forward. The architecture of complier can be checked by reading the size of void pointer.
The code below manages QT lib. It will check the current build environment, and store that value to QT_INSTALLED_PATH. That path is the path that you was asked by QT’s installer wizard. To change the QT installed path, change the value in QT_INSTALLED_PATH.
Note that the WIN32 refer to both Windows 32 bit and Windows 64 bit.
The code below manages BOOST lib.Similar to that of QT, the code is very straight forward. Make sure that you have installed boost to the correct path. Please check “b2” argument and BOOST_INSTALLED_PATH.
The code below will compile and link the source codes to the exe file.
And, here are the codes in mainwindows.cpp and .h file
Generating the Native Build Project
In this sesssion, I will show you how generate the native build project defined in CMakeList.txt.
- Open the “cmake-gui” then click “Browse Source” to fill “Where is the source code” field. Then, click “Browse build” to fill “Where to build the binaries” as shown in Figure 1.
- Click “configure” and select your compiler. In this tutorial, external libraries (Boost and QT) binaries are “MSVC-12.0” on windows and “GCC” on Linux. Thus, to make this tutorial working. For Windows, please select “Visual Studio 12 2013”. For Linux, please select “Unix Makefiles” as shown in Figure 2.
Building the Generated Project
Open the command prompt, cd to the “Where to build the binaries” directory.
For windows, Run the vcvarshell.bat to prepare environment for MSbuild. Then, build the project. See comands below.Figure 4 Running the App on windows
Figure 5 Running the app on Kubuntu Linux
Developing and Debugging under IDE
For windows, the MSVC project will contain both debug and release configuration.
To run the app, you must add QT’s Dll to the development environment.On Solution Explorer, right click at the “Simple App” project, choose properties.
Then add the path to the QT binaries in Configuration Properties > Debugging > Environment. Please see Figure 6.
Type the QT path such as “path=%path%;C:\QtMSVCx86\QT5.4.1\5.4\msvc2014_opengl\bin” to that field. Before start debugging, right click at “SimpleApp” project and choose “Set as Startup project”. The running project should be able to hit the break point as shown in Figure 7.

Figure 7 Debuging the app on visual studio (Windows) Figure 8 Set build type to Debug 
Figure 9 Debuging the app on code block (Kubuntu Linux) Packaging
You might notice that in order to run the app, one must add the environment path to QT’s dll (set path=%path%. ). Otherwise, you must copy the depended DLL and QML to the app’s directory. You can use dependency walker to find out which .dll you needs. Then, ship your app with those dlls. You can use CMakeList.txt to copy the dlls to the installing package. To do so, install “WIX toolset”. Grasp it from here Wix toolset. The code below is the CMakeList.txt that generate the WIX’s project files and finally create the .msi installer.
Finally, you can build the installer package by build the “PACKAGE.vcproj”. Figure 10 shows the default instller UI of the built app.
Disscusion
Creating cross-platfrom C++ project is not that difficult in these days. The setup may take time, but you will do this only once. Most of the code on CMakeList.txt are just if-else statement for choosing the right lib for compiler/OS. Adding new source file or referring to the module in external library are very easy. It is as simple as adding assambly reference in C#.
If you are looking for the way to build Boost by CMake, please read this discussion: http://stackoverflow.com/questions/18354398/what-is-the-best-way-to-build-boost-with-cmake
I am also looking for the best solution for building Boost too.Update 26-03-2015: I have just found out that boost signal2 is header-only library (but boost signal1 does not). So, I add boost thread to the tutorial project. To ensure that the build system really use static lib.
If you have any trouble on following this tutorial, please inform me.