0 安装XCode
在appStore中查找XCode,点击安装
1 安装Boost
Boost是一个功能强大、构造精巧、跨平台、开源并且完全免费的C++程序库,有着“C++‘准’标准库”的美誉,值得每位C++程序员学习使用。
1.1 使用源码安装(下载地址:http://www.boost.org/ 这里下载的是最新的Version 1.73.0,按照网上推荐的方式,在执行sudo ./b2的时候报错b2命令不存在。后来通过百度网盘下载1.63.0的版本,也报错。后来换成macport安装了)
- 下载Boost源码
- 解压放在任意目录,例如
/usr/local/boost_1_63_0
./bootstrap.sh
./b2
- 留意运行日志头文件目录
/usr/local/boost_1_63_0
, lib目录/usr/local/boost_1_63_0/stage/lib
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
vins-mobile的推荐方法是
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
1.3 使用MacPorts安装
MacPorts,曾经叫做DarwinPorts,是一个软件包管理系统,用来简化Mac OS X和Darwin操作系统上软件的安装。它是一个用来简化自由软件/开放源代码软件的安装的自由/开放源代码项目,与Fink和BSD类ports套件的目标和功能类似。跟BSD中的ports道理一样。MacPorts就像apt-get、yum一样,可以快速安装些软件。
- 下载安装MacPorts
sudo port install boost
基于安装包安装
访问官方网站http://www.macports.org/install.php,这里提供有dmg安装和源码安装两种方式,下载对应系统版本的安装包,下一步下一步安装即可。
没任何技术含量,只为混个脸熟。
下载后是一个 .pkg 扩展名的文件 ,双击运动安装向导;
安装成功后在/opt/local/include 以及/opt/local/lib 有boost的相关头文件和链接库。
Mac下/usr/local目录默认是对于Finder是隐藏,如果需要到/usr/local下去,打开Finder,然后使用command+shift+G,在弹出的目录中填写/usr/local就可以了。
4.MacPorts 基本应用
打开终端,直接执行“port”会因为版本信息,按“q”退出
$ port
MacPorts 2.4.1
Entering shell mode... ("help" for help, "quit" to quit)
[/opt] > q
Goodbye
5. 配置Xcode
(1)新建一个工程
(2)配置头文件和链接库
点击项目->TARGETS->Build Settings->Search Pahts->Header Search Paths和Library Search Pahts
添加usr/local/include 以及/usr/local/lib
(3)添加需要的libboost_filesystem.a和libboost_system.a文件才能运行成功
点击项目->TARGETS->Build Phases->Link Binary With Libraries
打开/usr/local/lib 找到相应的.a文件拖进去
(4)添加代码
#include <iostream>
#include <boost/asio.hpp>
#include <boost/version.hpp>
int main(int argc, const char * argv[])
{
std::cout << "Boost版本:" << BOOST_VERSION << std::endl;
}
5.xcode导入vins-mobile工程
1、mao os 下 双击你项目文件中的 .xcodeproj 文件;或者打开Xcode 点击open other(之类的具体名字忘记了) 选择 你的项目工程文件; 还有就是在打开XCODE之后,在最上面的操作栏里选择FILE,点击OPEN。
1. Build
The code has been compiled on macOS Sierra with Xcode 8.3.1 and tested with iOS 10.2.1 on iPhone7 Plus.
1.1 Install boost for macOS(这个方法在前文介绍了,暂未采用,因为下不下来)
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install boost
1.2 Download specific opencv2.framework from here, then unzip it to VINS_ThirdPartyLib/opencv2.framework (Please make sure you haven't installed opencv for your OSX)(注意事项Mac下载下来之后自动解压.framework 的后缀没了,放到目录下,会包各种opencv的错误,后缀需要自己补上)
1.3 In your Xcode, select Product-> Scheme-> Edit Scheme-> Run-> Info, set Build Configuration to Release (not debug)
1.4 Slect your device(是选择自己的设备,不是simulator,不然会报libcere.a的错误) at upper left corner, then choose your device size at Main.storyboard, build and run
1.5 Compatible Devices and iOS version requiements
iPhone7 Plus, iPhone7, iPhone6s Plus, iPhone6s, iPad Pro
iOS 10.2.1 and above
1.6 更改代码使其支持iphone8 Plus
iphone机型检测UIDevice
import Foundation
let iphoneName : String = UIDevice.current.modelName
public extension UIDevice {
var modelName: String {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
switch identifier {
case "iPod5,1": return "iPod Touch 5"
case "iPod7,1": return "iPod Touch 6"
case "iPhone3,1", "iPhone3,2", "iPhone3,3": return "iPhone 4"
case "iPhone4,1": return "iPhone 4s"
case "iPhone5,1", "iPhone5,2": return "iPhone 5"
case "iPhone5,3", "iPhone5,4": return "iPhone 5c"
case "iPhone6,1", "iPhone6,2": return "iPhone 5s"
case "iPhone7,2": return "iPhone 6"
case "iPhone7,1": return "iPhone 6 Plus"
case "iPhone8,1": return "iPhone 6s"
case "iPhone8,2": return "iPhone 6s Plus"
case "iPhone8,4": return "iPhone SE"
case "iPhone9,1": return "iPhone 7"
case "iPhone9,2": return "iPhone 7 Plus"
case "iPhone9,3": return "美版、台版iPhone 7"
case "iPhone9,4": return "美版、台版iPhone 7 Plus"
case "iPhone10,1","iPhone10,4": return "iPhone 8"
case "iPhone10,2","iPhone10,5": return "iPhone 8 Plus"
case "iPhone10,3","iPhone10,6": return "iPhone X"
case "iPhone11,8": return "iPhone XR"
case "iPhone11,2": return "iPhone XS"
case "iPhone11,4","iPhone11,6": return "iPhone XS Max"
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4":return "iPad 2"
case "iPad3,1", "iPad3,2", "iPad3,3": return "iPad 3"
case "iPad3,4", "iPad3,5", "iPad3,6": return "iPad 4"
case "iPad4,1", "iPad4,2", "iPad4,3": return "iPad Air"
case "iPad5,3", "iPad5,4": return "iPad Air 2"
case "iPad2,5", "iPad2,6", "iPad2,7": return "iPad Mini"
case "iPad4,4", "iPad4,5", "iPad4,6": return "iPad Mini 2"
case "iPad4,7", "iPad4,8", "iPad4,9": return "iPad Mini 3"
case "iPad5,1", "iPad5,2": return "iPad Mini 4"
case "iPad6,7", "iPad6,8": return "iPad Pro"
case "AppleTV5,3": return "Apple TV"
case "i386", "x86_64": return "Simulator"
default: return identifier
}
}
}
参考博客:https://blog.csdn.net/waterbinbin/article/details/62438417