我有一个c++项目,我想转换成一个web应用程序。为此,我想使用Emscripten来构建这个项目。
该项目使用了一些外部库。我成功地编译或找到了大多数库的JavaScript版本,现在我只能继续使用Boost库了。实际上,我甚至不知道如何启动Boost:他们使用引导脚本生成文件来构建库。可以将工具集传递给此脚本,但显然不支持Emscripten。
我的项目使用Boost的以下部分:线程、Regex、FileSystem、信号、系统。如何使用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;
~~^发布于 2013-03-31 18:22:49
我终于成功地用emscripten编译了所需的库。以下是我遵循的步骤。
征文的变化
编辑system/include/libcxx/climits以添加以下定义(参见http://github.com/kripken/emscripten/issues/531):
#ifndef CHAR_BIT
# define CHAR_BIT __CHAR_BIT__
#endif
#ifndef CHAR_MIN
# define CHAR_MIN (-128)
#endif
#ifndef CHAR_MAX
# define CHAR_MAX 127
#endif
#ifndef SCHAR_MIN
# define SCHAR_MIN (-128)
#endif
#ifndef SCHAR_MAX
# define SCHAR_MAX 127
#endif
#ifndef UCHAR_MAX
# define UCHAR_MAX 255
#endif
#ifndef SHRT_MIN
# define SHRT_MIN (-32767-1)
#endif
#ifndef SHRT_MAX
# define SHRT_MAX 32767
#endif
#ifndef USHRT_MAX
# define USHRT_MAX 65535
#endif
#ifndef INT_MAX
# define INT_MAX __INT_MAX__
#endif
#ifndef INT_MIN
# define INT_MIN (-INT_MAX-1)
# define INT_MIN (-INT_MAX-1)
#endif
#ifndef UINT_MAX
# define UINT_MAX (INT_MAX * 2U + 1)
#endif
#ifndef LONG_MAX
# define LONG_MAX __LONG_MAX__
#endif
#ifndef LONG_MIN
# define LONG_MIN (-LONG_MAX-1)
#endif
#ifndef ULONG_MAX
# define ULONG_MAX (LONG_MAX * 2UL + 1)
#endif在system/include/libcxx/cwchar中添加以下行
#include <cstdio>将Boost编译为共享库
正如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/emscripten/em++" ;
}强制BOOST_HAS_SCHER_YIELD在boost/config/posix_features.hpp,在第67行。
然后编译库:./b2 thread regex filesystem signals system
将Boost编译为静态库
执行上述所有步骤,然后编辑tools/build/v2/tools/gcc.jam并替换:
toolset.flags gcc.archive .AR $(condition) : $(archiver[1]) ;使用
toolset.flags gcc.archive .AR $(condition) : "/full/path/to/emscripten/emar" ;和
toolset.flags gcc.archive .RANLIB $(condition) : $(ranlib[1]) ;使用
toolset.flags gcc.archive .RANLIB $(condition) :
"/full/path/to/emscripten/emranlib" ;编译库:./b2 link=static variant=release threading=single runtime-link=static thread signals system filesystem regex
发布于 2017-12-11 10:47:16
作为记录,Boost现在包括了一个"emscripten“工具集,它(根据我的经验)使得上面描述的过程变得不必要了。
要正常使用boost,然后使用b2 (或bjam)编译,如下所示:
b2 toolset=emscripten https://stackoverflow.com/questions/15724357
复制相似问题