Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
What is the right way to bind a C++ class to javascript using emscripten and embind

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!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda