c++ - 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++
解决方案
我所要做的就是确保 boost lib 出现在 emscripten 包含目录中。在我的情况下,emsdk/fastcomp/emscripten/system/include/
我在那里创建了一个到系统'boost库的符号链接,一切都像一个魅力。
推荐阅读
- javascript - 无法在 react-redux 中调度事件
- python - 如何从后端向用户本地主机上的另一台服务器发出请求
- android - 带有 FragmentStateAdapter 嵌套滚动问题的 ViewPager2
- android - Android recyclerView问题——多层滚动内容?
- go - “标题”的目的 - 评论
- r - 编写复杂的函数
- javascript - 缩略图的背景颜色
- docker - Docker Image - apt get update -y 出错
- ravendb - 获取修订的总结果(RavenDB 客户端 API)
- bash - 如何在bash中将变量传递给awk以解析值