Install and use the Boost library on Mac under Mac

Source: Internet
Author: User
Tags serialization

Introduction to the Boost library: http://www.boost.org/

To use the Boost library to write applications on your Mac, you first need to install boost.

Installation steps: Refer to the official website tutorial http://www.boost.org/doc/libs/1_57_0/more/getting_started/unix-variants.html


1. Download Download boost_1_57_0.tar.bz2.

2. Unzip
Console operation name: Tar--bzip2-xf/path/to/boost_1_57_0.tar.bz2

You can also double-click tar.bz2 Unzip and then move to the directory you want to put.

3. Some components can be used directly after the completion of 1 and 2, since many are directly written in the HPP inline function, but to take advantage of other functions, you need to build the various components of the Boost library (step 4-6)

4. Enter the extracted directory CD PATH/TO/BOOST_1_57_0

5. Enter the./bootstrap.sh-prefix= "Install directory" input to remove the quotation marks, where the input is/users/yang/development/programfiles/boostinstallation

6. Enter./B2 install about 10 minutes to wait

Note: If the 5th step is entered directly./bootstrap.sh is installed by default in the Include and Lib directories under/usr/local, and/usr is a hidden directory under Macintosh HD.

Although you can enter a path inside the finder. It is best to install it in a directory that is displayed by default.

This boost is installed on the computer and can be programmed using it.


The following sections describe ways to use boost programming with Xcode and CMake under Mac.

MAC uses Xcode to create boost apps
=========================================================
1. Create a console application with Xcode, and after writing the code, in the project->build settings->search Paths->header search Paths and library search Paths the include and Lib directories that were generated in the tutorial above
2. In the project->build Phases->link Library with libraries dot Plus, select option, find the above Lib directory, select the file that ends with. A, add it

CMake creating a boost application
=========================================================
1. Write the CPP file
2. Write CmakeList.txt, pay attention to the inside
Set (boost_components iostreams Thread Filesystem Regex serialization signals System Timer)
Find_package (Boost 1.57.0 Components ${boost_components})
IOStreams thread and the like are all boost components, complete in the Lib directory, for example LIBBOOST_IOSTREAMS.A IOStreams is the component name, is not case-sensitive. If the configuration is not correct, CMake can pass, make error undefined symbols for architecture x86_64

Full CmakeList.txt:

Cmake_minimum_required (VERSION 2.6) project (boost) add_executable (boost Boost.cpp) set (boost_include_dirs "/users/ Yang/development/programfiles/boostinstallation/include ") Set (boost_libraries"/users/yang/development/ Programfiles/boostinstallation/lib ") Set (boost_components iostreams Thread Filesystem Regex Serialization signals System Timer) Set (Boost_use_static_libs on) set (boost_use_multithreaded on) set (Boost_use_static_runtime OFF) find_ Package (Boost 1.57.0 ${boost_components}) if (Boost_found) include_directories (${boost_include_dirs}) Target_link_libraries (Boost ${boost_libraries}) endif ()
This allows you to execute the CMake and make commands in turn to build the executable application.

Install and use the Boost library on Mac under Mac

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.