码迷,mamicode.com
首页 > 系统相关 > 详细

Ubuntu操作系统下使用CLion运行Boost库的一系列配置

时间:2019-04-21 22:57:06      阅读:880      评论:0      收藏:0      [点我收藏+]

标签:ref   local   环境变量   efi   direct   link   ase   test   使用   

一、下载安装Boost库

wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_64_0.tar.gz
tar zxvf boost_1_64_0.tar.gz
cd boost_1_64_0.tar.gz
./bootstrap.sh --with-libraries=all --with-toolset=gcc ##--with-libraries指定编译哪些boost库,all的话就是全部编译,只想编译部分库的话就把库的名称写上,之间用 , 号分隔即可,可指定的库下面介绍。--with-toolset指定编译时使用哪种编译器,Linux下使用gcc即可,如果系统中安装了多个版本的gcc,在这里可以指定gcc的版本,比如--with-toolset=gcc-4.4

命令执行完后看到如下所示即为成功:

Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.6
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...

Bootstrapping is done. To build, run:

    ./b2

To adjust configuration, edit project-config.jam.
Further information:

   - Command line help:
     ./b2 --help

   - Getting started guide: 
     http://www.boost.org/more/getting_started/unix-variants.html

   - Boost.Build documentation:
     http://www.boost.org/build/doc/html/index.html

二、编译

./b2 toolset=gcc

三、将编译的文件放到指定目录

./b2 install --prefix=/usr  
##--prefix=/usr用来指定boost的安装目录,不加此参数的话默认的头文件在/usr/local/include/boost目录下,库文件在/usr/local/lib/目录下。
这里把安装目录指定为--prefix=/usr则boost会直接安装到系统头文件目录和库文件目录下,可以省略配置环境变量。

四、对库进行编译

ldconfig

五、配置CMakeLists.txt文件

# cmake版本
cmake_minimum_required(VERSION 3.7)

# 项目名
project(Containers_test)

# 使用的编译器 C++11
set(CMAKE_CXX_STANDARD 11)

# 生成名字为Containers_test的可执行文件,执行main.cpp)
set(SOURCE_FILES main.cpp)
add_executable(Containers_test ${SOURCE_FILES})
set(BOOST_ROOT "/usr/local/include/boost")

#添加头文件搜索路径
include_directories(/usr/local/include)

#添加库文件搜索路径
link_directories(/usr/local/lib)

#用于将当前目录下的所有源文件的名字保存在变量 DIR_SRCS 中
aux_source_directory(. DIR_SRCS)


#在这里根据名字boost_thread去寻找libboost_thread.a文件
#改为自己的项目生成的可执行文件
target_link_libraries(Containers_test boost_thread boost_system)

 

Ubuntu操作系统下使用CLion运行Boost库的一系列配置

标签:ref   local   环境变量   efi   direct   link   ase   test   使用   

原文地址:https://www.cnblogs.com/parzulpan/p/10747562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!