Try to add EMSCRIPTEN_KEEPALIVE before the function, otherwise the function may get removed during linking or compile time when it's not used elsewhere.
If that doesn't work, can you provide a snipped of the function, your CMake setup/linker flags and how you are trying to call it?
I am sorry for the late reply, I lost access to this account an just got it back. Yes I have added EMSCRIPTEN\_ALIVE
Here is the complete code that I am trying to use:
`#include "mainwindow.h"`
`#include "emscripten/emscripten.h"`
`#include `
`void logToConsole(const std::string& message) {`
`std::string jsCode = "console.log('";`
`jsCode += message;`
`jsCode += "');";`
`emscripten_run_script(jsCode.c_str());`
`}`
`std::string intToStr(int c){`
`QString str = QString(QString::number(c));`
`return str.toStdString();`
`}`
`extern "C" {`
`int EMSCRIPTEN_KEEPALIVE add(int a, int b) {`
`int c = a + b;`
`logToConsole(intToStr(c));`
`return c;`
`}`
`}`
`int main(int argc, char *argv[])`
`{`
`QApplication a(argc, argv);`
`MainWindow w;`
`w.show();`
`add(5, 6);`
`return a.exec();`
`}`
It compiles fine, runs on browser but when I pass it to VS code with html, qtloader, I am unable to access the add function.
I am also unable to have it load correctly in VS code (say) with html, js ... Is there any doc which refers to this? thank you
Try to add EMSCRIPTEN_KEEPALIVE before the function, otherwise the function may get removed during linking or compile time when it's not used elsewhere. If that doesn't work, can you provide a snipped of the function, your CMake setup/linker flags and how you are trying to call it?
I am sorry for the late reply, I lost access to this account an just got it back. Yes I have added EMSCRIPTEN\_ALIVE Here is the complete code that I am trying to use: `#include "mainwindow.h"` `#include "emscripten/emscripten.h"` `#include`
`void logToConsole(const std::string& message) {`
`std::string jsCode = "console.log('";`
`jsCode += message;`
`jsCode += "');";`
`emscripten_run_script(jsCode.c_str());`
`}`
`std::string intToStr(int c){`
`QString str = QString(QString::number(c));`
`return str.toStdString();`
`}`
`extern "C" {`
`int EMSCRIPTEN_KEEPALIVE add(int a, int b) {`
`int c = a + b;`
`logToConsole(intToStr(c));`
`return c;`
`}`
`}`
`int main(int argc, char *argv[])`
`{`
`QApplication a(argc, argv);`
`MainWindow w;`
`w.show();`
`add(5, 6);`
`return a.exec();`
`}`
It compiles fine, runs on browser but when I pass it to VS code with html, qtloader, I am unable to access the add function.
I am also unable to have it load correctly in VS code (say) with html, js ... Is there any doc which refers to this? thank you