Linux system to compile boost library and use boost library in Qt creator __linux

Source: Internet
Author: User

<span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); ><span style= "White-space:pre" >	</span> recently configured the QT environment under Linux, and the project needs to use boost libraries, There are a lot of tutorials about using the Boost library in the QT creator of Linux to compile the Boost library and Linux system, but there is not a whole tutorial, for this reason, the following are all steps:</span>

1, download boost library, version optional, suggest the latest version

Address: http://sourceforge.net/projects/boost/files/boost/1.52.0/

2. Build Boost Library under Linux

Unzip the download good boost library;

Open the terminal, CD to boost library decompression directory, such as my:/home/you neme/boost_1_52_0

Execute command sudo./bootstrap.sh (Generate boost dedicated compilation tool here)

Execute command sudo./bjam Install

Wait for the installation to complete, will be in the/usr/local/include directory to generate Boost library header file (in fact, is a copy, because in the extract of the boost file there will be boost in the header file), under/usr/local/lib compiled to generate boost library files, This is the default build path, in order to be easy to use later, you can create a new stage file in the Extract directory/home/you neme/boost_1_52_0 of Boost library, Create a new Lib file inside the stage (I am doing it under windows because of Custom), and then copy the generated library files to/home/you neme/boost_1_52_0/stage/lib;

3. Use boost library in Qt creator (for example, using the thread library)

New Console Application

The code in the main program is as follows:

#include <QtCore/QCoreApplication>
#include <boost/thread.hpp>
#include <iostream>
using namespace Std;
void Hello ()
{
    cout<< "QT" <<endl;
}
int main (int argc, char *argv[])
{
    Qcoreapplication A (argc, argv);
    Boost::thread My_thread (&hello);
    My_thread.join ();
    return A.exec ();
}

Add boost header file path and library file path in the. Pro file as follows:

LIBS +=/HOME/XXX/BOOST_1_52_0/STAGE/LIB/LIBBOOST_THREAD.A

LIBS +=/HOME/XXX/BOOST_1_52_0/STAGE/LIB/LIBBOOST_SYSTEM.A

Note here, the use of Boost library in Qt must be added: (For specific reasons: http://blog.csdn.net/mangobar/article/details/52044778)

Defines +=boost_use_lib

Can be compiled and run

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.