I have a c++ project I would like to convert to a web application. For this purpose, I would like to use Emscripten to build the project.
The project uses some external libraries. I managed to compile or find the JavaScript version of most libraries and now I am stuck with the Boost ones. Actually I do not even know how to start for Boost: they use a boostrap script to generate the files to build the libraries. It is possible to pass the toolset to this script but Emscripten is obviously not supported.
My project uses the following parts of Boost: Thread, Regex, FileSystem, Signals, System. How can I compile these libraries using Emscripten?
Edit
按照 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;
~~^