Link errors with Boost port of header-only libraries for Emscripten in C++ / Wasm

1.1k Views Asked by At

I'm trying to compile a cpp file to make some tests with the Boost library in a Wasm project by using the existing Emscripten port:

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

When I use some of the Boost modules it works properly, like lambda in this example:

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

But when I use other modules like locale in this example, I get compilation errors:

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)

(both examples taken from the official documentation)

I compile the file with the -s USE_BOOST_HEADERS=1, which is the most straightforward way to do it as I have read in Emscripten ports documentation:

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

It seems I'm missing some includes or links but I don't know how to add them to the emcc command so that the compilation works. I already have the Boost library installed in my computer.

Thanks in advance!

Dani P.

EDIT: I just opened an issue in GitHub if is a port problem:

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

EDIT 2: The problem has to do with the Boost libraries that are not header-only, this is why lambda example works but locale not:

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

The no header-only libraries have to be compiled before included, but I don't know how to do it so it works with the emcc command. Any help please?

EDIT 2: I have checked that there is a locale.hpp file in the Boost folder so that it should work with the headers -s USE_BOOST_HEADERS=1.

I have tried adding this file and the locale folder to the compilation with -I but it doesn't work either, so I think it could be a port issue.

0

There are 0 best solutions below