iOS 集成mars xlog

xlog 是微信团队分享的基于 c/c++ 高可靠性高性能的运行期日志组件,官方 wiki 上集成的方式很简单,只需要执行build_ios.py脚本,选择Clean && build xlog.即可,但实际上还是有一些坑。

真机打包报错修复

shell 复制代码
Undefined symbols for architecture arm64:

  "_MD5", referenced from:

      strutil::BufferMD5(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) in mars[arm64][16](strutil.cc.o)

      strutil::BufferMD5(void const*, unsigned long) in mars[arm64][16](strutil.cc.o)

ld: symbol(s) not found for architecture arm64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

出现了_MD5这个Undefined symbols。这个符号是在mars/comm/strutil.cc文件里引入的。

cpp 复制代码
#include "openssl/md5.h"

// ...

std::string BufferMD5(const std::string &buf) {
    return BufferMD5(buf.data(), buf.size());
}

std::string BufferMD5(const void* buffer, size_t size) {
    uint8_t md5[MD5_DIGEST_LENGTH] = {0};
    MD5(static_cast<const unsigned char*>(buffer), static_cast<unsigned int>(size), md5);
    return strutil::MD5DigestToBase16(md5);
}

但在打包的时候,并没有把openssl 打进去。

方法一:自行依赖 openssl

想简单解决的话,可以自行依赖一个 openssl 的 pod 库。我这里试了下面这个版本,是可以正常运行的,虽然和mars 库里的似乎不是一个版本。

ruby 复制代码
pod 'OpenSSL-Universal', '1.0.2.20'

方法二:修改 mars 库

通过阅读源码,可以发现这个BufferMD5,在 xlog 里并没有使用到,只有打整个 mars 库的时候才会用到。可以简单通过宏定义,跳过相关的代码。

build脚本修改

python 复制代码
IOS_BUILD_SIMULATOR_XLOG_CMD = 'cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=SIMULATOR -DENABLE_ARC=0 -DENABLE_BITCODE=0 -DENABLE_VISIBILITY=1 -DMARS_XLOG_ONLY=1 && make -j8 && make install'
IOS_BUILD_OS_XLOG_CMD = 'cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS -DENABLE_ARC=0 -DENABLE_BITCODE=0 -DENABLE_VISIBILITY=1 -DMARS_XLOG_ONLY=1 && make -j8 && make install'

// 替换build_ios_xlog里的IOS_BUILD_OS_CMD和IOS_BUILD_SIMULATOR_CMD

CMakeLists.txt 修改

  • mars/comm/CMakeLists.txt
  • mars/CMakeLists.txt

修改代码

  • mars/comm/strutil.h
cpp 复制代码
#ifndef MARS_XLOG_ONLY
std::string BufferMD5(const void* buffer, size_t size);
std::string BufferMD5(const std::string& buf);
#endif
  • mars/comm/strutil.cc
cpp 复制代码
#ifndef MARS_XLOG_ONLY
#include "openssl/md5.h"
#endif

// ... 

#ifndef MARS_XLOG_ONLY
std::string BufferMD5(const std::string &buf) {
    return BufferMD5(buf.data(), buf.size());
}
@@ -338,6 +341,7 @@ std::string BufferMD5(const void* buffer, size_t size) {
    MD5(static_cast<const unsigned char*>(buffer), static_cast<unsigned int>(size), md5);
    return strutil::MD5DigestToBase16(md5);
}
#endif

还有个mars/comm/shuffle.h,依赖了openssl/rand.h,也需要处理下

cpp 复制代码
#ifndef MARS_XLOG_ONLY
// 头文件里的函数定义,这里就不放了
#endif

之后重新build framework 即可。

相关推荐
2501_915106321 小时前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106321 小时前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
熊猫钓鱼>_>2 小时前
移动端开发技术选型报告:三足鼎立时代的开发者指南(2026年2月)
android·人工智能·ios·app·鸿蒙·cpu·移动端
徐同保21 小时前
通过ip访问nginx的服务时,被第一个server重定向了,通过设置default_server解决这个问题
ios·iphone
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
夏幻灵2 天前
HTTPS全面解析:原理、加密机制与证书体
ios·iphone
TheNextByte12 天前
如何在iPhone上恢复已删除的笔记的综合指南
笔记·ios·iphone
rose and war2 天前
python和jinja版本问题导致的访问报500
python·ios
fendoudexiaoniao_ios2 天前
iOS 列表拖拽cell排序
ios·swift