mac环境boost安装和配置
mac安装boost
安装命令
brew install boost
安装的过程中会显示安装的位置:/usr/local/Cellar/boost/1.67.0_1
minbo:homebrew minbo$ brew install boost
Warning: boost 1.67.0_1 is already installed and up-to-date
To reinstall 1.67.0_1, run `brew reinstall boost`
minbo:homebrew minbo$ brew reinstall boost
==> Reinstalling boost
==> Downloading https://homebrew.bintray.com/bottles/boost-1.67.0_1.high_sierra.bottle.tar.gz
Already downloaded: /Users/lvminbo/Library/Caches/Homebrew/downloads/5c6f1153a81d34208116477fa3f0cbbc9bf45e3e22d2196e9eac2ff2b761656f--boost-1.67.0_1.high_sierra.bottle.tar.gz
==> Pouring boost-1.67.0_1.high_sierra.bottle.tar.gz
�� /usr/local/Cellar/boost/1.67.0_1: 13,506 files, 450.9MB
所以最终,头文件目录:/usr/local/Cellar/boost/1.67.0_1/include
lib目录:/usr/local/Cellar/boost/1.67.0_1/lib
使用boost
1. 利用CLion创建项目
2. 查看代码目录
minbo:boostTest minbo$ tree -I cmake-build-debug
.
├── CMakeLists.txt
└── main.cpp
3. 修改CMakeLists.txt文件,加入boost的头文件和lib
cmake_minimum_required(VERSION 3.12)
project(boostTest)
set(CMAKE_CXX_STANDARD 14)
#添加头文件搜索路径
include_directories(/usr/local/Cellar/boost/1.67.0_1/include)
#添加库文件搜索路径
link_directories(/usr/local/Cellar/boost/1.67.0_1/lib)
add_executable(boostTest main.cpp)
4.修改源文件
#include <iostream>
#include <boost/timer.hpp>
int main() {
std::cout << "Hello, World!" << std::endl;
boost::timer tm;
std::cout << tm.elapsed() << std::endl;
return 0;
}
5. 执行
程序正常运行,输出
/Users/lvminbo/allworkspace/CLionProjects/boost_asio/boostTest/cmake-build-debug/boostTest
Hello, World!
2e-06
Process finished with exit code 0