【发布时间】:2013-03-21 09:37:09
【问题描述】:
我有一个想要转换为 Web 应用程序的 c++ 项目。为此,我想使用 Emscripten 来构建项目。
该项目使用了一些外部库。我设法编译或找到了大多数库的 JavaScript 版本,现在我被 Boost 困住了。实际上我什至不知道如何开始使用 Boost:他们使用 boostrap 脚本来生成文件来构建库。可以将工具集传递给此脚本,但显然不支持 Emscripten。
我的项目使用 Boost 的以下部分:线程、正则表达式、文件系统、信号、系统。如何使用 Emscripten 编译这些库?
编辑
按照npclaudiu的回答,我用gcc工具包引导库,然后我编辑project-config.jam来配置编译器,替换:
# Compiler configuration. This definition will be used unless
# you already have defined some toolsets in your user-config.jam
# file.
if ! gcc in [ feature.values <toolset> ]
{
using gcc ;
}
与
# Compiler configuration. This definition will be used unless
# you already have defined some toolsets in your user-config.jam
# file.
if ! gcc in [ feature.values <toolset> ]
{
using gcc : : "/full/path/to/em++" ;
}
现在,输入 ./b2 可以有效地构建库。 Boost.Signals 和 Boost.System 编译良好。其他的有一些错误。
Boost.Thread 抱怨:
libs/thread/src/pthread/thread.cpp:503:27: error: use of undeclared identifier 'pthread_yield'
BOOST_VERIFY(!pthread_yield());
^
Boost.Regex 经常抱怨 CHAR_BIT 未声明,但这似乎是 emscripten 中的一个问题:
In file included from libs/regex/build/../src/c_regex_traits.cpp:28:
In file included from ./boost/regex/v4/c_regex_traits.hpp:26:
In file included from ./boost/regex/v4/regex_workaround.hpp:35:
/path/to/emscripten/system/include/libcxx/vector:1989:92: error: use of undeclared identifier 'CHAR_BIT'
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
^
Boost.FileSystem 似乎也因 emscripten 而失败:
In file included from libs/filesystem/src/windows_file_codecvt.cpp:21:
/path/to/emscripten/system/include/libcxx/cwchar:117:9: error: no member named 'FILE' in the global namespace
using ::FILE;
~~^
【问题讨论】:
-
网页后端还是前端?
-
它将是前端。这是一款我想在网络浏览器中玩的游戏。
-
只是好奇,编译为 emscripten 代码时需要多少 MB 的 Boost? :D
标签: javascript c++ boost emscripten