Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link errors when compiling cpp file with emcc -s USE_BOOST_HEADERS=1 in Windows #3

Open
twopelu opened this issue Feb 20, 2021 · 7 comments

Comments

@twopelu
Copy link

twopelu commented Feb 20, 2021

I'm trying to compile a cpp file to make some tests with the Boost library port for Emscripten in C++ but I get link errors when trying to compile it in Windows with the emcc command.

I think I'm missing some includes or links but I can't find the way to make it work and I can't find any documentation except the Emcscripten guide:

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

I have seen other posts with solutions for cmake but for for plain emcc in Windows.

Code

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

Emcc

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

Errors

 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)
@twopelu
Copy link
Author

twopelu commented Feb 21, 2021

I have found that Locale library is not header-only so it should be compiled as per Boost documentation. How can this be done with emcc so that the ported library can be linked?

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

@twopelu
Copy link
Author

twopelu commented Mar 7, 2021

I have found that Locale library is not header-only so it should be compiled as per Boost documentation. How can this be done with emcc so that the ported library can be linked?

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

I was wrong, I think Locale should work with headers only flag because there is a locale.hpp file. Maybe it is missing in the port? Is there any way to add it to the compilation? (I have tried with -I but it doesn't work either).

@sbc100
Copy link

sbc100 commented Mar 7, 2021

If the library was header-only then you wouldn't get link errors. Undefined symbols at link time mean you are missing some compiled code.

The USE_BOOST_HEADERS option that emcc has, and the port that lives in tools/ports/boost_headers.py is obviously limited in that only supplied headers. If you want to link aginst libraries that are not header-only you would need to build and link your own copy of boost (i.e. and avoid using the USE_BOOST_HEADERS option), or update the tools/ports/boost_headers.py to include and build sources too.

@FrozenSource
Copy link

Hi Guys,

@twopelu Did you ever get this working? I am trying to use boost-locale but as you specified some libraries unlike for example unordered_set (which I succeeded in) are not header only libraries.... however they are provided by the port which in that case is a bit strange.

@sbc100 I am trying to accomplish this all with cmake and as such will need to run cross-platform. I don't know how I would go about modifying that boost_headers.py file to accomplish getting these non-header only libraries to work in WASM. Can you provide any help in this?

Sincerely,

@sbc100
Copy link

sbc100 commented Jan 7, 2022

We try to avoid using cmake in tools/ports because we don't want to have dependencies on cmake and make/ninja there. We just compile the sources we need using ports.run_commands() and ports.create_lib(). See the other ports such as zlib.py for an example of how to do this.

It could be the you will want to avoid boost_headers.py completely and instead write you own external script to build and install boost inside the emscripten sysroot.

@twopelu
Copy link
Author

twopelu commented Jan 7, 2022

Hi Guys,

@twopelu Did you ever get this working? I am trying to use boost-locale but as you specified some libraries unlike for example unordered_set (which I succeeded in) are not header only libraries.... however they are provided by the port which in that case is a bit strange.

Sincerely,

Hi @FrozenSource, I gave up, I was not able to make it work, but I would like to get back to it if somebody finds the way :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants