无法在Emscripten环境下从源码构建Boost Graph库
Boost Graph库Emscripten构建失败问题排查
我正尝试使用Emscripten从源码构建Boost库,我的CMake可执行项目依赖以下Boost库:
- Boost::boost
- Boost::filesystem
- Boost::program_options
- Boost::graph
使用的构建命令如下:
git clone --recursive https://github.com/boostorg/boost.git --branch boost-1.85.0 cd boost ./bootstrap.sh ./b2 --show-libraries # 此处确认graph、filesystem和program_options均已列出 ./b2 toolset=emscripten link=static variant=release threading=multi runtime-link=static filesystem program_options graph
执行最后一条命令时出现错误:
don't know how to make <e>graph ...found 1 target... ...can't find 1 target...
省略graph参数后,Boost库可正常构建。
问题根源在于:Boost Graph是纯头文件库,不需要通过b2编译构建。Boost库分为两种类型:
- 编译型库:比如filesystem、program_options,这类库需要通过b2编译生成二进制文件,因此可以在b2命令中指定目标名称。
- 头文件型库:比如graph、algorithm,这类库所有实现都在头文件里,不需要编译生成二进制,因此b2没有对应的构建目标,指定后就会报错。
修正后的构建命令只需保留需要编译的库:
./b2 toolset=emscripten link=static variant=release threading=multi runtime-link=static filesystem program_options
构建完成后,在CMake项目中正常引入Boost::graph目标即可,CMake会自动处理头文件路径依赖,无需额外链接二进制库。
内容的提问来源于stack exchange,提问作者andynewman
相关产品推荐
相关产品推荐

