0

我正在尝试编译一个 cpp 文件,以使用现有的Emscripten 端口在 Wasm 项目中使用 Boost 库进行一些测试:

https://github.com/emscripten-ports/boost

当我使用一些 Boost 模块时,它可以正常工作,例如本例中的lambda

https://www.boost.org/doc/libs/1_75_0/more/getting_started/windows.html#build-a-simple-program-using-boost

但是,当我在本例中使用其他模块(如locale)时,会出现编译错误:

https://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/hello_8cpp-example.html

 D:\DANI\wasm\boostsuite>emcc boost_suite.cpp -s USE_BOOST_HEADERS=1 -s LLD_REPORT_UNDEFINED -o target/boost_suite.html
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::generator::generator()
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::generator::~generator()
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::generator::generate(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> > const&) const
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::get(std::__2::ios_base&)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::display_flags(unsigned long long)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::get(std::__2::ios_base&)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::display_flags(unsigned long long)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::get(std::__2::ios_base&)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::display_flags(unsigned long long)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::get(std::__2::ios_base&)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::display_flags(unsigned long long)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::get(std::__2::ios_base&)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::domain_id() const
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::converter<char>::id
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::details::format_parser::format_parser(std::__2::ios_base&, void*, void (*)(void*, std::__2::locale const&))
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::details::format_parser::set_one_flag(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> > const&, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> > const&)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::details::format_parser::get_position()
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::details::format_parser::~format_parser()
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::ios_info::get(std::__2::ios_base&)
    wasm-ld: error: C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o: undefined symbol: boost::locale::details::format_parser::restore()
    wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
    emcc: error: 'D:/DANI/wasm/emsdk/upstream/bin\wasm-ld.exe -o target/boost_suite.wasm C:\Users\dani\AppData\Local\Temp\emscripten_temp_7wl1l58q\boost_suite_0.o -LD:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libboost_headers.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libgl.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libal.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libhtml5.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++-noexcept.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++abi-noexcept.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libdlmalloc.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a D:\DANI\wasm\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=C:\Users\dani\AppData\Local\Temp\tmp2cj831u_.undefined --strip-debug --export main --export emscripten_stack_get_end --export emscripten_stack_get_free --export emscripten_stack_init --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export fflush --export __errno_location --export malloc --export free --export setThrew --export-table -z stack-size=5242880 --initial-memory=16777216 --entry=main --max-memory=16777216 --global-base=1024' failed (1)

(两个例子都取自官方文档)

我使用-s USE_BOOST_HEADERS=1编译文件,这是我在 Emscripten 端口文档中阅读的最直接的方法:

https://emscripten.org/docs/compiling/Building-Projects.html#emscripten-ports

https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-link-against-system-libraries-like-sdl-boost-etc

emcc boost_suite.cpp -s USE_BOOST_HEADERS=1 -s LLD_REPORT_UNDEFINED -o target/boost_suite.html

似乎我缺少一些包含或链接,但我不知道如何将它们添加到 emcc 命令以便编译工作。我已经在我的计算机中安装了 Boost 库。

提前致谢!

丹尼·P。

编辑:如果是端口问题,我刚刚在 GitHub 中打开了一个问题:

https://github.com/emscripten-ports/boost/issues/3

编辑 2:问题与不是仅标头的 Boost 库有关,这就是 lambda 示例有效但语言环境无效的原因:

https://www.boost.org/doc/libs/1_55_0/more/getting_started/windows.html#header-only-libraries

在包含之前必须编译没有仅包含头文件的库,但我不知道该怎么做,所以它可以与 emcc 命令一起使用。请问有什么帮助吗?

编辑 2:我检查locale.hpp了 Boost 文件夹中有一个文件,以便它可以与 headers 一起使用-s USE_BOOST_HEADERS=1

我尝试将此文件和语言环境文件夹添加到编译中,-I但它也不起作用,所以我认为这可能是一个端口问题。

4

0 回答 0