Replies: 2 comments 2 replies
-
Firstly, yes, you should always use the In terms of interacting with the C/C++ code there is really no difference bettween how you do it under node and in the browser. There are several methods you can use: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html For simple C call I recommend just using call/cwrap, or just calling the exports directly. For more complex C++ interactions you should use embind. The |
Beta Was this translation helpful? Give feedback.
-
Ok, the main problem stemmed from me needing to add the EmScripten include directory directly to my build. Thanks. I also needed to use the following options on my
This allowed me to straighten out some really difficult issues when using the CJS generated wasm loader file in an ES6 project, and in using the resulting One other thing. I would make the need to call the DOC NOTES The problem is for a newbie is that the EmScripten docs are somewhat overwhelming and given the polymorphic nature of much of this powerful library (e.g. - I hope I don't seem ungrateful. EmScriptem and Binaryen together are a tremendous body of work and have given me the ability to use C++ code from my JavaScript apps, an amazing feat. Thank you for your effort. |
Beta Was this translation helpful? Give feedback.
-
I just spent several hours going through different paths in the documentation that talk about different ways to build and call code. Unfortunately I find myself confused as to what is the quickest path for me to actually get my C++ module working with Node.js.
I installed EmScripten and Binaryen without trouble and they both work. I then use
emcc
to compile my self-contained C++ module and header file and I get out two files:a.out.js
anda.out.wasm
. But I can't seem to get from here to something I can use.First I tried the code from this page after changing the
wasm
file path to my actual path and changing the exports to those in my C++ code:https://nodejs.org/en/learn/getting-started/nodejs-with-webassembly
But that resulted in an error complaining that
imports
were not defined.Then I tried running and tracing the
a.out.js
file withnode.exe
. It runs fine, but when I traced deep into the code, the resultModule/instance
did not show the C++ class from my C++ file at all. All I saw were what looked to be a lot of C++ library function stubs/proxy-calls for C++ library functions that I assume thewasm
module can use.So what is the simplest path for me to be able to create one of the C++ class objects from Node.js code (not browser)?
Do I need to list the class and each of its public methods and data members in the
EXPORTED_fUNCTIONS
argument toemcc
?Or do I use an
EMBINDINGS
declaration in my C++ file to do the same? If so, should I put that declaration in my "h" or "cpp" file and is there a way to use it so I can still compile the code in my IDE (CLion) without the CLang-Tidy throwing an error on it? When I tried that approach the compiler showed errors like these:I also do not know what the correct string is to use for the opt level declaration EMSCRIPTEN_BINDINGS(SoftFold). Do I just repeat the class name?
a.out.js
file in some manner that I don't understand yet?As I said, I could really use a tutorial or brief instructions that show me how to use
emcc
and any necessaryEmScriptem
idioms to create mywasm
module, and then another brief text on how to call it.Beta Was this translation helpful? Give feedback.
All reactions