What is the right way to bind a C++ class to javascript using emscripten and embind

Viewed 160

I am currently attempting to bind a C++ class and its method (eventually, multiple methods but for now one isn't working) to javascript. I am currently using a separate interface.cpp file to handle all of the C++ bindings for clarity. This is what the file looks like.

#include <emscripten/bind.h>
#include "board.h"

using namespace emscripten;

EMSCRIPTEN_BINDINGS(my_module){
    class_<Board>("Board")
        .constructor()
        .function("MakeMove", &Board::MakeMove);
}

board.h is a header file that contains a Board class as well as the associated methods. I am attempting to compile my project with this command: emcc --bind src/* -I include -I ../emsk/emsdk/upstream/include/ src/* just contains all of my .cpp source files and include/ contains all of my header files. When I run it, I receive this error:

emcc --bind src/* -I include -I ../emsk/emsdk/upstream/include/
src/interface.cpp:8:10: error: no matching member function for call to 'function'
        .function("MakeMove", &Board::MakeMove);
        ~^~~~~~~~
/home/sethbassetti/emsk/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:1567:44: note: candidate template ignored: couldn't infer template argument 'Callable'
    EMSCRIPTEN_ALWAYS_INLINE const class_& function(const char* methodName, Callable callable, Policies...) const {
                                           ^
1 error generated.
emcc: error: '/home/sethbassetti/emsk/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=1 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/home/sethbassetti/emsk/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -Iinclude -I../emsk/emsdk/upstream/include/ src/interface.cpp -c -o /tmp/emscripten_temp_gfg6j40o/interface_2.o' failed (returned 1)

I am not sure what the issue is since I am following documentation for embind almost exactly to link C++ classes to javascript. I have played around with many different versions of this and nothing seems to be able to perform this class + method binding. Any help would be appreciated!

0 Answers
Related