Skip to content

implicit instantiation of undefined template #11274

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

Open
lkashef opened this issue May 28, 2020 · 9 comments · May be fixed by #12973
Open

implicit instantiation of undefined template #11274

lkashef opened this issue May 28, 2020 · 9 comments · May be fixed by #12973

Comments

@lkashef
Copy link

lkashef commented May 28, 2020

Hello there 👋 I maintaining a core atom package and the CI looks like it's been stuck for a while, it was downloading a version-less portable emscripten sdk and activating version sdk-1.37.9-64bit

implicit instantiation of undefined template 'emscripten::internal::RegisterClassConstructor<emscripten::val>'

Full Error (click to expand).
emcc: warning: Assuming object file output in the absence of `-c`, based on output filename. Add with `-c` or `-r` to avoid this warning [-Wemcc]
 
In file included from src/bindings/em/patch.cc:5:
 
/Users/distiller/project/emsdk-1.39.16/upstream/emscripten/system/include/emscripten/bind.h:1466:13: error: implicit instantiation of undefined template 'emscripten::internal::RegisterClassConstructor<emscripten::val>'
 
            invoker::template invoke<ClassType, Policies...>(callable);

src/bindings/em/patch.cc:86:6: note: in instantiation of function template specialization 'emscripten::class_<Patch, emscripten::internal::NoBaseClass>::constructor<emscripten::val, Patch *(*)(emscripten::val), emscripten::allow_raw_pointers>' requested here
 
    .constructor<emscripten::val>(WRAP_STATIC(&constructor), emscripten::allow_raw_pointers())   
/Users/distiller/project/emsdk-1.39.16/upstream/emscripten/system/include/emscripten/bind.h:1219:16: note: template is declared here
 
        struct RegisterClassConstructor;

I saw another issue that looks related but sadly there are no answers from the community.

For reference that's the PR I created on the target repo to update the emscripten dependencies and resolve the build issues, in case you would like the setup before and after, feel free to build this locally by following the same steps in .github/workflows/build.yml


that's the exact reference the compiler is complaining about, I am not entirely sure if the problem is related to this line or not but seems related to the way of overloading the constructor.

@kripken kripken added the embind label May 28, 2020
@kripken
Copy link
Member

kripken commented May 28, 2020

cc @jgravelle-google

@lkashef
Copy link
Author

lkashef commented Jun 12, 2020

Hello again folks 👋 did anyone get the time to take a look at this?

@vbora
Copy link

vbora commented Jun 18, 2020

This might help in debugging the root cause.
I too got the same error when I had set -std=c++1z, it went away when I use -std=c++11

@aminya
Copy link
Contributor

aminya commented Oct 31, 2020

I can reproduce this error with emsdk 2.0.8.

As mentioned, there is this patch file tries to use the internals of emscripten. Maybe there is something going on here. I am familiar with these API.

https://github.com/atom/superstring/blob/1198557f2b853065373a3b1c1e019f2125424db3/src/bindings/em/patch.cc#L86

Here is the reproduction:

git clone https://github.com/aminya/superstring -b bump-xcode-on-circleci
cd superstring
mkdir -p build

Build (in bash):

#!/usr/bin/env bash

mkdir -p build

## Compile pcre

emcc                                         \
  -O3                                        \
  -I vendor/pcre/10.23/src                   \
  -I vendor/pcre/include                     \
  -D HAVE_CONFIG_H                           \
  -D PCRE2_CODE_UNIT_WIDTH=16                \
  -c                                         \
  vendor/pcre/pcre2_chartables.c             \
  vendor/pcre/10.23/src/pcre2_auto_possess.c \
  vendor/pcre/10.23/src/pcre2_compile.c      \
  vendor/pcre/10.23/src/pcre2_config.c       \
  vendor/pcre/10.23/src/pcre2_context.c      \
  vendor/pcre/10.23/src/pcre2_dfa_match.c    \
  vendor/pcre/10.23/src/pcre2_error.c        \
  vendor/pcre/10.23/src/pcre2_find_bracket.c \
  vendor/pcre/10.23/src/pcre2_jit_compile.c  \
  vendor/pcre/10.23/src/pcre2_maketables.c   \
  vendor/pcre/10.23/src/pcre2_match.c        \
  vendor/pcre/10.23/src/pcre2_match_data.c   \
  vendor/pcre/10.23/src/pcre2_newline.c      \
  vendor/pcre/10.23/src/pcre2_ord2utf.c      \
  vendor/pcre/10.23/src/pcre2_pattern_info.c \
  vendor/pcre/10.23/src/pcre2_serialize.c    \
  vendor/pcre/10.23/src/pcre2_string_utils.c \
  vendor/pcre/10.23/src/pcre2_study.c        \
  vendor/pcre/10.23/src/pcre2_substitute.c   \
  vendor/pcre/10.23/src/pcre2_substring.c    \
  vendor/pcre/10.23/src/pcre2_tables.c       \
  vendor/pcre/10.23/src/pcre2_ucd.c          \
  vendor/pcre/10.23/src/pcre2_valid_utf.c    \
  vendor/pcre/10.23/src/pcre2_xclass.c

mv *.o build/

emar                         \
  rcs build/pcre.a           \
  build/*.o

rm build/*.o

### Compile superstring

em++                                    \
  --bind                                \
  -o browser.js                         \
  -O3                                   \
  -xc++                                 \
  -std=c++11							\
  -I src/bindings/em                    \
  -I src/core                           \
  -I vendor/libcxx                      \
  -I vendor/pcre/include                \
  -D PCRE2_CODE_UNIT_WIDTH=16           \
  --pre-js src/bindings/em/prologue.js  \
  --post-js src/bindings/em/epilogue.js \
  src/core/*.cc                         \
  src/bindings/em/*.cc                  \
  build/pcre.a                          \
  -s TOTAL_MEMORY=134217728             \
  --memory-init-file 0                  \
  "$@"

@aminya
Copy link
Contributor

aminya commented Dec 5, 2020

Here is a minimal example to reproduce the issue. Can someone please look into this?

It is not possible to make a class constructor that accepts a JavaScript object as the input!

mwe.cpp

#include<emscripten/bind.h>

struct MyStruct {
  bool optionA;
  MyStruct(bool _optionA): optionA{_optionA} {};
};

MyStruct *constructor_(emscripten::val value) {
  bool optionA = false;
  if (value.as<bool>() && value["optionA"].as<bool>()) {
    optionA = true;
  }
  return new MyStruct(optionA);
}

EMSCRIPTEN_BINDINGS(MyStruct) {
  emscripten::class_<MyStruct>("MyStruct")
      .constructor<emscripten::val>(&constructor_);
}
em++ --bind -o mwe.js  -std=c++17  -O0 ./mwe.cpp  --memory-init-file 0

cc: @kripken @jgravelle-google

@polx
Copy link

polx commented Apr 8, 2022

Having met the same error text I came here.

I reconstructed the example of class binding at embind and had a hard time... until I realized that there was a tiny little itch in my reproduction: the getter needs a const after it. I assume that this is to allow a safer js-view of the C-struct.

This is independent of having a constructor or not.
I think that there's some pretty deep magic happening into the compiler so that these errors are reported... feels like we're doing currying processes between type-systems and actual deduction...

@chenzx
Copy link

chenzx commented May 27, 2022

I want to embind a C++ class with its self pointer as constructor arg:

class A {
public:
   A(A* other){...}
};

use

class_<A>("A")
        .constructor<A*>(allow_raw_pointers())

& have the same problem...

@sasmaster
Copy link

Any update on this one? I have the same issue here.

@tthef
Copy link

tthef commented Dec 20, 2023

For anyone who lands here looking for solutions trying to overload a class constructor using the 'constructor<emscripten::val>' construct, which unfortunately comes up top in google search on the subject, this construct is not valid with recent emscripten, you have to use a factory function instead, as described in the docs, https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#external-constructors.

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

Successfully merging a pull request may close this issue.

8 participants