You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS Ventura13.4下如何用CMake安装rapidjson C++库?

在MacOS Ventura 13.4上通过CMake安装rapidjson的解决方案

你遇到的编译错误是因为MacOS的Clang编译器默认将sprintf标记为废弃函数,而rapidjson的CMake配置默认开启了-Werror(把警告当作错误处理),导致示例代码里的sprintf触发编译失败。以下是两种解决办法,以及完整的CMake安装流程:

方法一:跳过编译示例项目(推荐)

安装rapidjson核心库时,示例代码并非必需,直接禁用示例编译即可:

git clone https://github.com/Tencent/rapidjson.git
git submodule update --init
cd rapidjson
mkdir build && cd build
# 禁用示例编译
cmake .. -DRAPIDJSON_BUILD_EXAMPLES=OFF
make
# 安装到系统目录(需要sudo权限)
sudo make install

方法二:忽略废弃函数警告

如果确实需要编译示例,可以通过CMake参数关闭deprecated-declarations的警告错误:

git clone https://github.com/Tencent/rapidjson.git
git submodule update --init
cd rapidjson
mkdir build && cd build
# 添加编译选项忽略废弃函数警告
cmake .. -DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations"
make
sudo make install

安装后在自己的CMake项目中使用

安装完成后,在你的项目CMakeLists.txt中可以这样引入rapidjson:

find_package(RapidJSON REQUIRED)
include_directories(${RAPIDJSON_INCLUDE_DIRS})

add_executable(your_app main.cpp)

内容的提问来源于stack exchange,提问作者mascai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 23:24:57