<i id='jpxbC'><tr id='jpxbC'><dt id='jpxbC'><q id='jpxbC'><span id='jpxbC'><b id='jpxbC'><form id='jpxbC'><ins id='jpxbC'></ins><ul id='jpxbC'></ul><sub id='jpxbC'></sub></form><legend id='jpxbC'></legend><bdo id='jpxbC'><pre id='jpxbC'><center id='jpxbC'></center></pre></bdo></b><th id='jpxbC'></th></span></q></dt></tr></i><div id='jpxbC'><tfoot id='jpxbC'></tfoot><dl id='jpxbC'><fieldset id='jpxbC'></fieldset></dl></div>

    <legend id='jpxbC'><style id='jpxbC'><dir id='jpxbC'><q id='jpxbC'></q></dir></style></legend>
      <bdo id='jpxbC'></bdo><ul id='jpxbC'></ul>

    <small id='jpxbC'></small><noframes id='jpxbC'>

    1. <tfoot id='jpxbC'></tfoot>

      将 Boost 与 Emscripten 结合使用

      时间:2023-07-20
    2. <tfoot id='59oRw'></tfoot>

      <small id='59oRw'></small><noframes id='59oRw'>

        <bdo id='59oRw'></bdo><ul id='59oRw'></ul>
          <legend id='59oRw'><style id='59oRw'><dir id='59oRw'><q id='59oRw'></q></dir></style></legend>

              1. <i id='59oRw'><tr id='59oRw'><dt id='59oRw'><q id='59oRw'><span id='59oRw'><b id='59oRw'><form id='59oRw'><ins id='59oRw'></ins><ul id='59oRw'></ul><sub id='59oRw'></sub></form><legend id='59oRw'></legend><bdo id='59oRw'><pre id='59oRw'><center id='59oRw'></center></pre></bdo></b><th id='59oRw'></th></span></q></dt></tr></i><div id='59oRw'><tfoot id='59oRw'></tfoot><dl id='59oRw'><fieldset id='59oRw'></fieldset></dl></div>
                  <tbody id='59oRw'></tbody>
              2. 本文介绍了将 Boost 与 Emscripten 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个 C++ 项目,我想将其转换为 Web 应用程序.为此,我想使用 Emscripten 来构建项目.

                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.

                该项目使用了一些外部库.我设法编译或找到了大多数库的 JavaScript 版本,现在我坚持使用 Boost 版本.实际上我什至不知道如何开始 Boost:他们使用 boostrap 脚本来生成文件来构建库.可以将工具集传递给此脚本,但显然不支持 Emscripten.

                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.

                我的项目使用 Boost 的以下部分:线程、正则表达式、文件系统、信号、系统.如何使用 Emscripten 编译这些库?

                My project uses the following parts of Boost: Thread, Regex, FileSystem, Signals, System. How can I compile these libraries using Emscripten?

                编辑

                按照npclaudiu的回答,我用gcc工具包引导库,然后我编辑project-config.jam来配置编译器,替换:

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

                # 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 编译良好.其他人有一些错误.

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

                Boost.Thread 抱怨:

                Boost.Thread complains:

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

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

                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 似乎也因 emscripten 而失败:

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

                推荐答案

                我终于设法用 emscripten 编译了所需的库.这是我遵循的步骤.

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

                编辑 system/include/libcxx/climits 以添加以下定义(参见 http://github.com/kripken/emscripten/issues/531):

                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
                

                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/config/posix_features.hpp 中强制 BOOST_HAS_SCHER_YIELD,在第 67 行附近.

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

                然后编译库:./b2 thread regex filesystem signals system

                执行以上所有步骤,然后编辑tools/build/v2/tools/gcc.jam并替换:

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

                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

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

                上一篇:如何使用 boost 条件变量等待线程完成处理? 下一篇:升压库

                相关文章

                  <bdo id='J10bx'></bdo><ul id='J10bx'></ul>

                1. <i id='J10bx'><tr id='J10bx'><dt id='J10bx'><q id='J10bx'><span id='J10bx'><b id='J10bx'><form id='J10bx'><ins id='J10bx'></ins><ul id='J10bx'></ul><sub id='J10bx'></sub></form><legend id='J10bx'></legend><bdo id='J10bx'><pre id='J10bx'><center id='J10bx'></center></pre></bdo></b><th id='J10bx'></th></span></q></dt></tr></i><div id='J10bx'><tfoot id='J10bx'></tfoot><dl id='J10bx'><fieldset id='J10bx'></fieldset></dl></div>

                  1. <small id='J10bx'></small><noframes id='J10bx'>

                    <legend id='J10bx'><style id='J10bx'><dir id='J10bx'><q id='J10bx'></q></dir></style></legend><tfoot id='J10bx'></tfoot>