macOS 中Boost的安装和使用
1 安装Boost
1.1 使用源码安装
- 下载Boost源码
- 解压放在任意目录,例如
/home/wang/ ./bootstrap.sh,默认的位置是在usr/local下面;可以通过--prefix="绝对路径"来指定./b2 install- 留意运行日志头文件目录
/usr/local/include, lib目录/usr/local/lib
打开源码中index.html查看使用文档
1.2 使用Homebrew安装
- 下载安装HomeBrew
brew install boost- 留意运行日志会显示头文件目录
/usr/local/Cellar/boost/1.60.0_2/include, lib目录/usr/local/Cellar/boost/1.60.0_2/lib
1.3 使用MacPort安装
- 下载安装MacPort
sudo port install boost
2. 在XCode项目中使用Boost
- 新建一个Command Line Tool项目
- 在Build Setings - Header Search Paths 增加头文件目录
- 替换main.cpp中代码,运行!输入任意数字回车可看到结果。
#include <iostream>
#include <boost/lambda/lambda.hpp>
int main(int argc, const char * argv[]) {
printf("Please input any number:");
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
return 0;
}
3. 在XCode项目中使用Boost Lib库
Boost的很多功能都是直接在hpp头文件里实现的,比如上面的lambda例子不用导入任何lib就可以运行了。但也有一部分需要依赖指定lib库才能使用。比如下面这个正则表达式的例子:
#include <iostream>
#include <boost/regex.hpp>
int main(int argc, const char * argv[]) {
std::string str = "2013-08-15";
boost::regex rex("(?<year>[0-9]{4}).*(?<month>[0-9]{2}).*(?<day>[0-9]{2})");
boost::smatch res;
std::string::const_iterator begin = str.begin();
std::string::const_iterator end = str.end();
if (boost::regex_search(begin, end, res, rex))
{
std::cout << "Day: " << res ["day"] << std::endl
<< "Month: " << res ["month"] << std::endl
<< "Year: " << res ["year"] << std::endl;
}
}
3.1 使用静态库
在Build Setings - Other linker flags /usr/local/boost_1_63_0/stage/lib/libboost_regex.a
使用命令行编译相当于
c++ -I /usr/local/boost_1_63_0 main.cpp -o main /usr/local/boost_1_63_0/stage/lib/libboost_regex.a
./main
如果这里直接使用lboost_regex, Xcode默认加载动态库。实际运用中可以考虑将目录中的动态库删除,只保留静态库,并在Build Setings - Library Search Paths 增加lib文件目录。
3.2 使用动态库
- 在Build Setings - Library Search Paths 增加lib文件目录
- 将lib文件目录中的libboost_regex.dylib文件拖入项目
- 确保在Build Phases - Link Bindary With Libraries中已经有该库
- 在Build Phases - Copy Files, 复制libboost_regex.dylib到Products Directory
使用命令行编译相当于
c++ -I /usr/local/boost_1_63_0 main.cpp -o main -L/usr/local/boost_1_63_0/stage/lib/ -lboost_regex
cp /usr/local/boost_1_63_0/stage/lib/libboost_regex.dylib ./
./main
macOS 中Boost的安装和使用的更多相关文章
- 在 MacOS 中使用 multipass 安装 microk8s 环境
在 MacOS 中使用 multipass 安装 microk8s 环境 Multipass & MicroK8s 介绍 What is Kubernetes? Kubernetes clus ...
- macOS中安装docker
如官方文档中所说: 1.点击进入boot2docker/osx-installer release页面. 2.在下载页面中点击 Boot2Docker-x.x.x.pkg 来下载 Boot2Docke ...
- Boost下载安装编译配置使用指南
转载:http://www.cppblog.com/jerryma/archive/2011/10/17/158554.html --更新于2011/7/19,目前我已对boost的安装和使用有了新的 ...
- luarocks在macOS系统上的安装
luarocks是基于lua开发的一个包管理工具,所以在安装luarocks之前需要先安装lua(见博客同目录下“lua在MacOS系统上的安装”).具体的安装步骤如下: 1.源码安装部署luaroc ...
- macOS 中使用 phpize 动态添加 PHP 扩展的错误解决方法
使用 phpize 动态添加 PHP 扩展是开发中经常需要做的事情,但是在 macOS 中,首次使用该功能必然会碰到一些错误,本文列出了这些错误的解决方法. 问题一: 执行 phpize 报错如下: ...
- 在MacOS中,Unity使用VSCode开发,4.7版本无法正常使用C#
我在MacOS中安装了两个版本的Unity,一个是4.7版本,一个是5.6版本,在5.6版本中使用VSCode打开项目时,可以正常代码提示和查看,但是打开4.7版本的项目时,无法正常提示和查看. 经过 ...
- python学习--Linux下dlib安装(主要是cmake和boost的安装)
昨天我们使用了dlib和opencv进行了人脸检测标注(http://www.cnblogs.com/take-fetter/p/8310298.html) 但是运行环境是基于windows的而且可能 ...
- MacOS中升级openssl
MacOS中升级openssl ➜ ~ brew instal openssl 使用情况中始终发现,openssl并没有真正升级 在/usr/local/Cellar/openssl/目录中 ...
- 汇编语言实验1 & macOS下DOSBox的安装
一.macOS下DOSBox的安装 1.在官网下载DOSBox-0.74.dmg 打开,此时默认z盘 一番折腾,终于搞定debug 然后为了不用每次都执行mount,遂更改配置文件自动挂在目录 再次打 ...
随机推荐
- 【自家测试】2017-12-16 FJOI2016 d1
1. 所有公共子序列问题(allcs.pas/c/cpp)★问题描述:一个给定序列的子序列是在该序列中删去若干元素后得到的序列.确切地说,若给定序列X= x 1 x 2 ... x m ,则另一序列Z ...
- 洛谷P4550 【收集邮票】
题目链接: 神仙题QAQ 题目分析: 概率期望题是不可能会的,一辈子都不可能会的QAQ 这个题也太仙了 首先明确一下题意里面我感觉没太说清楚的地方,这里是抽到第\(i\)次要\(i\)元钱,不是抽到第 ...
- vue2 + koa2全栈部署
1.首先打包前端上传 修改config下的index.js 代理地址为服务器IP index: path.resolve(__dirname, '../dist/index.html'), asset ...
- Template-Thymeleaf:Thymeleaf
ylbtech-Template-Thymeleaf:Thymeleaf 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 0. https://www.thyme ...
- 《DSP using MATLAB》Problem 8.2
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- Python学习day18-常用模块之NumPy
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- JSON对象获取指定元素以及JSON.parse() 与 JSON.stringify() 的区别
利用 JSON.parse(param) 实现 例: var param = { "name" : "张三", "text" : { &qu ...
- 2019-5-21-C#-命令行如何静默调用-del-删除文件
title author date CreateTime categories C# 命令行如何静默调用 del 删除文件 lindexi 2019-05-21 11:32:28 +0800 2019 ...
- CSP-S模拟41影子,玫瑰花精题解
题面:https://www.cnblogs.com/Juve/articles/11523567.html 影子: 暴力方法:枚举每一对点暴力统计最小权 优化:考虑并查集,枚举每个点,如果没有被访问 ...
- BZOJ3907 网格 卡特兰数
题目描述 某城市的街道呈网格状,左下角坐标为A(0, 0),右上角坐标为B(n, m),其中n >= m. 现在从A(0, 0)点出发,只能沿着街道向正右方或者正上方行走,且不能经过图示中直线左 ...