我有一个C++项目,想要将其转化为Web应用程序。为此,我想使用Emscripten来构建该项目。
该项目使用了一些外部库。我已经成功编译或找到了大多数库的JavaScript版本,现在我卡在了Boost库上。实际上,我甚至不知道如何开始使用Boost:它们使用一个引导脚本来生成构建库所需文件。可以向此脚本传递工具集,但是明显不支持Emscripten。
我的项目使用了以下Boost组件:Thread、Regex、FileSystem、Signals、System。如何使用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;
~~^