使用Boost与Emscripten [英] Using Boost with Emscripten

查看:1177
本文介绍了使用Boost与Emscripten的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++项目,我想转换到Web应用程序。为此,我想用Emscripten构建项目。

该项目使用一些外部库。我设法编译或发现大多数图书馆的JavaScript版本,现在我坚持使用Boost的。事实上,我甚至不知道如何下手的提升:他们使用的自举脚本生成的文件来构建库。这是可能的工具集传递给该脚本,但显然是不支持Emscripten

我的项目使用升压的以下部分:螺纹,正则表达式,文件系统,信号系统。我如何使用Emscripten编译这些库?

修改

继npclaudiu的答案,我自举库与海湾合作委员会工具包,然后我编辑项目config.jam中来配置编译器,替换:

 #编译器配置。该定义将被使用,除非
#你已经在你的用户定义config.jam中的一些工具集
#文件。
如果! GCC在[feature.values​​<&工具GT; ]
{
    使用gcc;
}

 #编译器配置。该定义将被使用,除非
#你已经在你的用户定义config.jam中的一些工具集
#文件。
如果! GCC在[feature.values​​<&工具GT; ]
{
    用gcc:/全/路径/要/ EM ++;
}

现在,键入 ./ B2 有效地构建库。 Boost.Signals和Boost.System编译好。该有的都有了一些错误。

Boost.Thread抱怨:

 库/线程/ src目录/的pthread / thread.cpp:503:27:错误:使用未声明的标识符pthread_yield的
        BOOST_VERIFY(pthread_yield()!);
                      ^

Boost.Regex抱怨了很多关于CHAR_BIT是未声明的,但它似乎是在emscripten一个问题:

28:

 在文件从库/正则表达式/建造/../的src / c_regex_traits.cpp包括:
在文件从./boost/regex/v4/c_regex_traits.hpp:26包括:
在文件从./boost/regex/v4/regex_workaround.hpp:35包括:
/路径/到/ emscripten /系统/有/ libcxx /向量:1989:92:错误:使用未声明的标识符CHAR_BIT的
静态常量无符号__bits_per_word =的static_cast<无符号>(sizeof的(__ STORAG​​E_TYPE)* CHAR_BIT);
                                                                                       ^

Boost.Filesystem的似乎失败归因于emscripten太:

21:

 在文件从库/文件系统/ src目录/ windows_file_ codecvt.cpp包括:
/路径/到/ emscripten /系统/有/ libcxx / cwchar:117:9:错误:没有在全局命名空间命名为FILE成员
使用::文件;
      ~~ ^


解决方案

我终于成功地编译emscripten需要的库。下面是我遵循的步骤。

的变化emscripten

修改系统/有/ libcxx / climits 来添加下面的定义(见<一href=\"http://github.com/kripken/emscripten/issues/531\">http://github.com/kripken/emscripten/issues/531):

 的#ifndef CHAR_BIT
#定义CHAR_BIT __CHAR_BIT__
#万一CHAR_MIN的#ifndef
#定义CHAR_MIN(-128)
#万一的#ifndef CHAR_MAX
#定义CHAR_MAX 127
#万一的#ifndef SCHAR_MIN
#定义SCHAR_MIN(-128)
#万一的#ifndef SCHAR_MAX
#定义SCHAR_MAX 127
#万一的#ifndef UCHAR_MAX#定义UCHAR_MAX 255
#万一的#ifndef SHRT_MIN
#定义SHRT_MIN(-32767-1)
#万一的#ifndef SHRT_MAX
#定义SHRT_MAX 32767
#万一的#ifndef USHRT_MAX
#定义USHRT_MAX 65535
#万一的#ifndef INT_MAX
#定义INT_MAX __INT_MAX__
#万一INT_MIN的#ifndef
#定义INT_MIN(-INT_MAX-1)
#定义INT_MIN(-INT_MAX-1)
#万一的#ifndef UINT_MAX
#定义UINT_MAX(INT_MAX * 2U + 1)
#万一的#ifndef LONG_MAX
#定义LONG_MAX __LONG_MAX__
#万一的#ifndef LONG_MIN
#定义LONG_MIN(-LONG_MAX-1)
#万一的#ifndef ULONG_MAX
#定义ULONG_MAX(LONG_MAX * 2UL + 1)
#万一

添加以下行系统/有/ libcxx / cwchar

 的#include&LT; cstdio&GT;

编译升压共享库

正如npclaudiu建议,使用GCC工具引导库。然后编辑项目config.jam中来配置编译器和替换:

 #编译器配置。该定义将被使用,除非
#你已经在你的用户定义config.jam中的一些工具集
#文件。
如果! GCC在[feature.values​​&LT;&工具GT; ]
{
    使用gcc;
}

 #编译器配置。该定义将被使用,除非
#你已经在你的用户定义config.jam中的一些工具集
#文件。
如果! GCC在[feature.values​​&LT;&工具GT; ]
{
    用gcc:/全/路径/要/ emscripten / EM ++;
}

强制 BOOST_HAS​​_SCHER_YIELD 升压/配置/ posix_features.hpp ,围绕线67。

然后编译库: ./ B2线的正则表达式的文件系统信号系统

编译升压为静态库

做到以上步骤,然后编辑工具/建设/ V2 /工具/ gcc.jam 并替换:

  toolset.flags gcc.archive .AR $(条件):$(归档[1]);

  toolset.flags gcc.archive .AR $(条件):/全/路径/要/ emscripten / EMAR

  toolset.flags gcc.archive .RANLIB $(条件):$(ranlib的[1]);

  toolset.flags gcc.archive .RANLIB $(条件):
  /全/路径/要/ emscripten / emranlib

编译库: ./ B2链接=静态变量=释放线程=单个运行时链接=静态线程信号系统的文件系统的正则表达式

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

Following the answer of npclaudiu, I bootstrapped the library with the gcc toolkit, then I edited project-config.jam to configure the compiler, replacing:

# 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 ;
}

with

# 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++" ;
}

Now, typing ./b2 effectively builds the libraries. Boost.Signals and Boost.System compile well. The others have some errors.

Boost.Thread complains:

libs/thread/src/pthread/thread.cpp:503:27: error: use of undeclared identifier 'pthread_yield'
        BOOST_VERIFY(!pthread_yield());
                      ^

Boost.Regex complains a lot about CHAR_BIT to be undeclared but it seems to be a problem in 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 seems to fail due to emscripten too:

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;
      ~~^

解决方案

I finally managed to compile the needed libraries with emscripten. Here are the steps I followed.

Changes in emscripten

Edit system/include/libcxx/climits to add the following definitions (see 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

Add the following line in system/include/libcxx/cwchar

#include <cstdio>

Compiling Boost as shared libraries

As suggested by npclaudiu, bootstrap the library using the gcc toolkit. Then edit project-config.jam to configure the compiler and replace:

# 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 ;
}

with

# 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++" ;
}

Force BOOST_HAS_SCHER_YIELD in boost/config/posix_features.hpp, around the line 67.

Then compile the libraries: ./b2 thread regex filesystem signals system

Compiling Boost as static libraries

Do all the above steps, then edit tools/build/v2/tools/gcc.jam and replace:

toolset.flags gcc.archive .AR $(condition) : $(archiver[1]) ;

with

toolset.flags gcc.archive .AR $(condition) : "/full/path/to/emscripten/emar" ;

and

toolset.flags gcc.archive .RANLIB $(condition) : $(ranlib[1]) ;

with

toolset.flags gcc.archive .RANLIB $(condition) :
  "/full/path/to/emscripten/emranlib" ;

Compile the libraries: ./b2 link=static variant=release threading=single runtime-link=static thread signals system filesystem regex

这篇关于使用Boost与Emscripten的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆