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

Linux下NDK/clang++结合Boost交叉编译Android的头文件检索问题

交叉编译Android端svg++封装库的头文件搜索问题

背景

  • 我开发了一套封装svg的库,svg本身是纯头文件库,依赖的Boost组件也全部为头文件形式,不需要链接任何Boost预编译二进制文件。
  • 目前该库已经完成Linux、Windows平台的编译构建,接下来需要交叉编译适配Android平台。
  • 初步方案是在Linux环境下直接使用NDK,搭配本地Linux系统安装的Boost完成交叉编译,不确定该方案是否可行。

遇到的异常

实际测试编译时出现报错,提示找不到Boost头文件:

[1/2] Building CXX object CMakeFiles/svgpp-source.dir/src/svgparser.cpp.o 
FAILED: CMakeFiles/svgpp-source.dir/src/svgparser.cpp.o  
/home/iwarv/AndroidSDK/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android22 -I/home/iwarv/git/svgpp-source/include -I/home/iwarv/git/svgpp-source/extern/svgpp/include -I/home/iwarv/git/svgpp-source/extern/svgpp/third_party/rapidxml_ns -funwind-tables -no-canonical-prefixes -fexceptions -frtti -stdlib=libc++ -O2 -g -DNDEBUG -fPIC -std=gnu++17 -MD -MT CMakeFiles/svgpp-source.dir/src/svgparser.cpp.o -MF CMakeFiles/svgpp-source.dir/src/svgparser.cpp.o -o CMakeFiles/svgpp-source.dir/src/svgparser.cpp.o -c /home/iwarv/git/svgpp-source/src/svgparser.cpp 
In file included from /home/iwarv/git/svgpp-source/src/svgparser.cpp:4: 
In file included from /home/iwarv/git/svgpp-source/extern/svgpp/include/svgpp/policy/xml/rapidxml_ns.hpp:12: 
In file included from /home/iwarv/git/svgpp-source/extern/svgpp/include/svgpp/definitions.hpp:12: 
/home/iwarv/git/svgpp-source/extern/svgpp/include/svgpp/utility/boost_parameter_fixed.hpp:10:10: fatal error: 'boost/version.hpp' file not found 
#include <boost/version.hpp>

按照常规认知,编译器默认会搜索/usr/include目录,不需要额外通过-I参数指定路径。测试发现如果在上述编译命令中手动显式添加-I/usr/include参数,就能通过这一阶段的编译。

排查过程

执行以下命令查看NDK自带clang++的默认头文件搜索路径:

~/AndroidSDK/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -v -E -

命令输出显示默认搜索路径确实包含/usr/include:

#include <...> search starts here:
 /usr/local/include
 /home/iwarv/AndroidSDK/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/11.0.5/include
 /usr/include/x86_64-linux-gnu
 /usr/include

补充验证

已经确认Boost头文件确实安装在/usr/include目录下,执行查找命令的结果中包含目标文件:

find /usr/include -name version.hpp
... 多个匹配结果,包含...
/usr/include/boost/version.hpp

目前需要明确两个问题:一是直接复用本地Linux的Boost头文件交叉编译Android库的方案是否可行,二是出现上述路径搜索异常的根本原因。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.27 02:39:09