#error: implicit instantiation of undefined template for std::basic_string on emscripten

36 messages · Page 1 of 1 (latest)

wicked cobalt
#

I am attempting to compile a project I've forked to emscripten. Compiling natively works fine. Compiling with the latest version of emsdk will cause a lot of errors along the lines of
error: implicit instantiation of undefined template 'std::char_traits<LibraryType>' and after trying to figure out what causes it, I think is attributed to there being classes such as class LibraryString : public std::basic_string<LibraryType> { . . . }

All "LibraryType"s used with std::basic_string are enums that represent characters, for instance, one is enum Unicode { . . . } (I'm not fully sure why this is done).

From what I understand, reading cppreference.com, the way forward would be to define templates of std::char_traits on the enums that are used by std::basic_string that fill out the static member functions required by it. Is this the right way?

But I'm confused why this implicit instantiation works on native compilation but suddenly breaks with emscripten, any ideas why this is the case?

shut flareBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

spice kettle
#

Probably forgot to include a header

#

Such as <string>

wicked cobalt
# spice kettle Such as `<string>`

Both files for LibraryType and LibraryString have <string> included before anything else. I went ahead and went through the files where the error happens and the ones they include that include LibraryString and added <string> before anything else and the same error pops up like:

In file included from <...>/Assert.cc:24:
<...>/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/string:834:42: error: implicit instantiation of undefined template 'std::char_traits<Unicode>'
  834 |   static_assert(is_same<_CharT, typename traits_type::char_type>::value,
      |                                          ^
<...>/UCS_string.hh:53:27: note: in instantiation of template class 'std::basic_string<Unicode>' requested here
   53 | class UCS_string : public std::basic_string<Unicode>
      |                           ^
<...>/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/__fwd/string.h:23:29: note: template is declared here
   23 | struct _LIBCPP_TEMPLATE_VIS char_traits;
      |                             ^
In file included from <...>/Assert.cc:24:
In file included from <...>/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/string:652:

Should note that Assert.cc doesn't even use UCS_string. I went through every header it includes that uses it and made sure <string> was included before UCS_string.hh was

uncut rose
#

oh wait that's not your code

#

that's a library

#

just report the bug to the library authors

wicked cobalt
#

I’m not sure if they intended it to compile to emscripten, this is GNU APL I’m modifying—so I think I’m doing undefined behavior on my own

wicked cobalt
#

I just used emcmake cmake .. and cmake --build with a CMakeLists I made that I found natively working. I'll go ahead and read through this to make sure I didn't miss anything

spice kettle
wicked cobalt
#

bruh

uncut rose
wicked cobalt
uncut rose
wicked cobalt
#

All of this was made from one guy from 2008-2024, I suppose it was useful… uhh.. 14 years ago?

#

I have no idea

wicked cobalt
#

!solved

shut flareBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

wicked cobalt
spice kettle
#

They probably used std::basic_string instead of std::vector for the small object optimization

#

Maybe you can juse replace every use basic_string with vector and it'll just work

wicked cobalt
uncut rose
#

right?

#

wait nvm, std::char_traits<T> works for any T with operator== apparently

spice kettle