首页 > 解决方案 > emscripten 和 boost 库:如何为 webassembly 编译现有项目?

问题描述

我有一个用 C++ 编写的现有项目,我想使用 emscripten 为 webassembly 进行编译。代码调用boost库:

#include <boost/program_options.hpp>

#include <iostream>
#include <string>
#include <exception>
#include <algorithm>
#include <iterator>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/thread/thread.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/assign.hpp>

我已经使用 emscripten 作为静态库编译了 boost 库的必要部分,并使用 emar 将它们从 bc 转换为 a 文件。现在我正在尝试用预编译的库来编译为编译器提供的项目:(Makefile 的一部分)

C_OPTIONS= -O3 -DNDEBUG -g \
           /home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/cmdline.bc.a \
           /home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/config_file.bc.a \
           /home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/convert.bc.a \
           /home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/libboost_program_options.bc.a \

但是 make 仍然抱怨代码中第一次出现 boost:

main.cpp:1:10: fatal error: 'boost/program_options.hpp' file not found
#include <boost/program_options.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting

这个问题可能听起来有点天真,但我该如何正确地做到这一点?该项目使用 g++ 编译得非常好,但不是 em++

标签: c++boostemscripten

解决方案


我所要做的就是确保 boost lib 出现在 emscripten 包含目录中。在我的情况下,emsdk/fastcomp/emscripten/system/include/我在那里创建了一个到系统'boost库的符号链接,一切都像一个魅力。


推荐阅读