title: Link errors with Boost port of header-only libraries for Emscripten in C++ / Wasm
body: <p>I'm trying to compile a cpp file to make some tests with the Boost library in a Wasm project by using the existing <strong>Emscripten port</strong>:</p>
  <p><a href="https://github.com/emscripten-ports/boost" rel="nofollow noreferrer">https://github.com/emscripten-ports/boost</a></p>
  <p>When I use some of the Boost modules it works properly, like <strong>lambda</strong> in this example:</p>
  <p><a href="https://www.boost.org/doc/libs/1_75_0/more/getting_started/windows.html#build-a-simple-program-using-boost" rel="nofollow noreferrer">https://www.boost.org/doc/libs/1_75_0/more/getting_started/windows.html#build-a-simple-program-using-boost</a></p>
  <p>But when I use other modules like <strong>locale</strong> in this example, I get compilation errors:</p>
  <p><a href="https://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/hello_8cpp-example.html" rel="nofollow noreferrer">https://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/hello_8cpp-example.html</a></p>
  <pre><code> D:\DANI\wasm\boostsuite&gt;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&lt;char, std::__2::char_traits&lt;char&gt;, std::__2::allocator&lt;char&gt; &gt; const&amp;) 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&amp;)
      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&amp;)
      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&amp;)
      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&amp;)
      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&amp;)
      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&lt;char&gt;::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&amp;, void*, void (*)(void*, std::__2::locale const&amp;))
      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&lt;char, std::__2::char_traits&lt;char&gt;, std::__2::allocator&lt;char&gt; &gt; const&amp;, std::__2::basic_string&lt;char, std::__2::char_traits&lt;char&gt;, std::__2::allocator&lt;char&gt; &gt; const&amp;)
      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&amp;)
      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)
  </code></pre>
  <p><em>(both examples taken from the official documentation)</em></p>
  <p>I compile the file with the <strong>-s USE_BOOST_HEADERS=1</strong>, which is the most straightforward way to do it as I have read in Emscripten ports documentation:</p>
  <p><a href="https://emscripten.org/docs/compiling/Building-Projects.html#emscripten-ports" rel="nofollow noreferrer">https://emscripten.org/docs/compiling/Building-Projects.html#emscripten-ports</a></p>
  <p><a href="https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-link-against-system-libraries-like-sdl-boost-etc" rel="nofollow noreferrer">https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-link-against-system-libraries-like-sdl-boost-etc</a></p>
  <pre><code>emcc boost_suite.cpp -s USE_BOOST_HEADERS=1 -s LLD_REPORT_UNDEFINED -o target/boost_suite.html
  </code></pre>
  <p>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.</p>
  <p>Thanks in advance!</p>
  <p>Dani P.</p>
  <p>EDIT: I just opened an issue in GitHub if is a port problem:</p>
  <p><a href="https://github.com/emscripten-ports/boost/issues/3" rel="nofollow noreferrer">https://github.com/emscripten-ports/boost/issues/3</a></p>
  <p><strike>EDIT 2: The problem has to do with <strong>the Boost libraries that are not header-only</strong>, this is why lambda example works but locale not:</p>
  <p><a href="https://www.boost.org/doc/libs/1_55_0/more/getting_started/windows.html#header-only-libraries" rel="nofollow noreferrer">https://www.boost.org/doc/libs/1_55_0/more/getting_started/windows.html#header-only-libraries</a></p>
  <p>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?</strike></p>
  <p>EDIT 2: I have checked that there is a <code>locale.hpp</code> file in the Boost folder so that it should work with the headers <code>-s USE_BOOST_HEADERS=1</code>.</p>
  <p>I have tried adding this file and the locale folder to the compilation with <code>-I</code> but it doesn't work either, so I think it could be a port issue.</p>