栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

iOS,mac基于源码编译以及使用BOOST库

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

iOS,mac基于源码编译以及使用BOOST库

1,下载源码

 下载并解压源码,下载路径(来自https://www.boost.org/users/download/),现在以1.77为例:https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.bz2

2,运行bootstrap.sh

解压进入booost库目录,命令行运行:

./bootstrap.sh

假如你只想编译某个库:

./bootstrap.sh --with-libraries=context
3,修改project-config.jam,在末尾增加一下内容:
# IOS ARM64
using clang : iphoneos
: xcrun clang -arch arm64 -stdlib=libc++ -std=c++11 -miphoneos-version-min=12.0 -fvisibility-inlines-hidden -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
;

# IOS x86_64
using clang : iphonesimulator
: xcrun clang -arch x86_64 -stdlib=libc++ -std=c++11 -miphoneos-version-min=12.0 -fvisibility-inlines-hidden -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
;
 4,编译处理单个库,把各个架构合并。例如libboost_context.a
lib=libboost_context.a
dir='stage/lib'

# Build arm64
./b2 -a -j4 toolset=clang-iphoneos binary-format=mach-o abi=aapcs link=static stage
mv $dir/$lib $dir/arm64_$lib

# Build x86_64
./b2 -a -j4 toolset=clang-iphonesimulator binary-format=mach-o abi=sysv link=static stage
mv $dir/$lib $dir/x86_64_$lib

# Make fat
lipo -create $dir/arm64_$lib $dir/x86_64_$lib -output $dir/$lib

5,编译多个库,把各个架构合并
dir='stage/lib'


# Build arm64
./b2 -a -j4 toolset=clang-iphoneos binary-format=mach-o abi=aapcs link=static stage
mkdir $dir/arm64
mv $dir/ $dir/arm64

# Build x86_64
./b2 -a -j4 toolset=clang-iphonesimulator binary-format=mach-o abi=sysv link=static stage
mkdir $dir/x86_64
mv $dir/ $dir/x86_64

# Make fat
for i in `find $dir/arm64 -name "*.a" -exec basename {} ;`
do
	echo $i 
	lipo -create $dir/arm64/$i $dir/x86_64/$i -output stage/lib/$i
done
6,测试
 
#include
using  namespace  boost; //名字空间

#include
using namespace std;

int main()
{ 
   //mt19937  马特赛特旋转演算法,适用于很多场景
   mt19937 mt(time(0));
   cout << "随机数范围" << mt.min() << "~" << mt.max() << endl;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/784233.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号