File Exchange

image thumbnail

Generate JavaScript Using MATLAB Coder

version 2.0.2 (956 KB) by Geoff McVittie
Create JavaScript/WebAssembly apps and libraries from MATLAB projects using MATLAB Coder.

36 Downloads

Updated 24 Oct 2019

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Generate JavaScript using MATLAB Coder Add-On in combination with the Emscripten compiler converts your MATLAB functions into high-performance, client-side JavaScript/WebAssembly apps and libraries. Generated code can be compiled, embedded, and run in any modern browser; including, Google Chrome, Mozilla FireFox, Microsoft Edge, and Apple Safari. The generated code can also be run in standalone JavaScript engines, such as NodeJS.

Cite As

Geoff McVittie (2021). Generate JavaScript Using MATLAB Coder (https://www.mathworks.com/matlabcentral/fileexchange/69973-generate-javascript-using-matlab-coder), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (61)

Oluwasegun Somefun

To support emsdk >= 2.0.4, the coder's toolchain configuration has to be modified to rectify the errors thrown on undefined symbols being referenced.
Hopefully, someone or Mathworks takes this up.

Oluwasegun Somefun

BUG:

Struggled with this for quite sometime, while trying out the MouseEvent, Event et al. Callback example in the CreateAppWithCallbacks demo example. The bug was a missing emxAPI header file during build compilation

SOLUTION:

%% 1.1 Fix dynamically allocated arrays to use EMXARRAY
% - Use this to prevent webcoder compile errors
% WebCoder Bug:
% - configured by author to use c-style emxarray data structure,
% as was probably, the default in 2019.
% - unfortunately, mathworks introduced coder::array class template to be
% the default, when target language is C++
%
% See:
% - https://www.mathworks.com/support/search.html/answers/516820-matlab-2020a-matlab-coder-use-c-style-emxarray-bug.html
% - https://www.mathworks.com/help/coder/ug/use-dynamically-allocated-cpps-arrays-in-generated-function-interfaces.html
ccfg = coder.load('CodeConfig.mat');
ccfg.codeConfig.DynamicMemoryAllocationInterface = 'C';
save('CodeConfig.mat', '-struct', 'ccfg');

Greg Hacker

...and one more question. To keep moving forward, I removed the parameters just to see what javascript gets created. I see there are cpp files created that have converted code for my dummy function that doesn't do anything really. But, only one js file is created that has a bunch of support functions and the only mention of my dummy function is this:
/** @type {function(...*):?} */
var _gregtestfunction = Module["_gregtestfunction"] = createExportWrapper("gregtestfunction");

I do not find any js files other than this and it doesnt' have any javascript code for the body of the function. (but the cpp file does.)

Greg Hacker

My Windows PC is now building the sample app! I may not know exactly what fixed it. I think this was the last changes:
- Performed a couple installs from the command line based on the errors (in emsdk folder), such as: emsdk install sdk-releases-upstream-89202930a98fe7f9ed59b574469a9471b0bda7dd-64bit
- emsdk_env.bat (there are sh versions for non-Windows)
- emsdk activate
I think one of the above two entries restored the latest version of emsdk and I didn't notice, so for a day I assumed it was on 1.40.1. Once I notice and re-installed with "emsdk install 1.40.1" then it started working. (use "emsdk list" to see what is installed)

I have not worked on the Mac to see why it doesn't build anything. It still just comes immedialty back to the command prompt when running the build command in MATLAB command window. Will look at that some other day.

Greg Hacker

@MarijnNijenhuis
@OluwasegunSomefun
@MariaMartinez
@GeoffMcVittie

Very odd! I tried to submit two messages in a row and it just replaces my previous message below. I submitted two messages previously last week just fine. So, now I will combine the two messages and hopefully that one sticks. I appologize if all of a suddent several duplicate messages appear.

I have a Mac and Windows PC for work. Both do not run the sample programs. Both have different problems.

-----------------------------------
For the Mac situation:
-----------------------------------

I started with the Mac and it was working except for the error on "start" and "render" that was previously reported by myself and others.

Before I was able to see the great responses from a few people below on using v1.40.1 emsdk and getting rid of spaces in paths, I tried many other things and I think I messed up my environment on the Mac. Now when I run the build step, it immediatly returns with no output. So, it appears to not be doing anything.

>> emsdkRootDir = webcoder.setup.getEmscriptenRootDirectory;
Emscripten SDK root folder provided:
/Users/E143543/Desktop/emsdk
>> webcoder.setup.verifyThirdPartyTools(emsdkRootDir);
EMSDK and external tools have been verified.
>> emsdkRootDir = webcoder.setup.getEmscriptenRootDirectory;
Emscripten SDK root folder provided:
/Users/E143543/Desktop/emsdk
>> webcoder.setup.verifyThirdPartyTools(emsdkRootDir);
EMSDK and external tools have been verified.
>> webcoder.setup.saveThirdPartyToolPaths(emsdkRootDir);
Third party toolpaths saved with WebCoder.
>> webcoder.setup.createAndRegisterToolchain;
Emscripten toolchain definition created.
Emscripten toolchain registered with MATLAB Coder.
>> proj = openProject(pwd);
>> webcoder.build.project(proj);
>> webcoder.build.project(proj);
>>

-----------------------------------
For the Windows situation:
-----------------------------------

i also have removed spaces and installed 1.40.1 of emsdk. When i run "emsdk list" in the emsdk directory, it shows that I only have "INSTALLED" next to that version and no other versions.

When I was running earlier today, I was getting the same rmdir error in destructor of onCleanup when I ran createAndRegisterToolchain and the build, but now I'm only getting it on the build. I would say that I was mistaken, but I had done a screen shot of the now missing error. I noticed that it also still has the start and render error as before even though 1.40.1 is installed and spaces were removed directories. (I also changed the preference for add-ons in MATLAB)

I am unsure if Geoff still works at matlab. He mentioned that his email was in the plug-in, but I have not found it.

Here is the output from Windows:

>> proj = openProject(pwd);
>> emsdkRootDir = webcoder.setup.getEmscriptenRootDirectory;
Emscripten SDK root folder provided:
C:\projects\emsdk
>> webcoder.setup.verifyThirdPartyTools(emsdkRootDir);
EMSDK and external tools have been verified.
>> webcoder.setup.saveThirdPartyToolPaths(emsdkRootDir);
Third party toolpaths saved with WebCoder.
>> webcoder.setup.createAndRegisterToolchain;
Emscripten toolchain definition created.
Emscripten toolchain registered with MATLAB Coder.
>> webcoder.build.project(proj);
Warning: The following error was caught while executing 'onCleanup' class destructor:
Error using rmdir
No directories were removed.

Error in coder.make.ToolchainInfo/validateToolchain>@()rmdir(tempDirName,'s')

Error in onCleanup/delete (line 81)
obj.task();

Error in coder.make.ToolchainInfo/validateToolchain

Error in coder.make.ToolchainInfo/validate

Error in coder.make.invokeBuilder

Error in coder.make.invokeBuilder

Error in RTW/genMakefileAndBuild (line 305)
buildResults = coder.make.invokeBuilder...

Error in coder.internal.doCompile

Error in emcBuildRTW

Error in emcBuildRTW

Error in emcGenMakefileAndBuild

Error in emcGenMakefileAndBuild

Error in emcBuildTarget

Error in emlcprivate

Error in coder.internal.compile

Error in emlckernel

Error in emlckernel

Error in emlckernel

Error in emlcprivate

Error in codegen

Error in webcoder.internal.coder.buildProject

Error in webcoder.build.project (line 18)
webcoder.internal.coder.buildProject(proj);
> In coder.make.ToolchainInfo/validateToolchain
In coder.make.ToolchainInfo/validate
In coder.make.invokeBuilder
In coder.make.invokeBuilder
In RTW/genMakefileAndBuild (line 305)
In coder.internal.doCompile
In emcBuildRTW
In emcBuildRTW
In emcGenMakefileAndBuild
In emcGenMakefileAndBuild
In emcBuildTarget
In emlcprivate
In coder.internal.compile
In emlckernel
In emlckernel
In emlckernel
In emlcprivate
In codegen
In webcoder.internal.coder.buildProject
In webcoder.build.project (line 18)
------------------------------------------------------------------------
Adding directories to PATH:
PATH += C:\projects\emsdk
PATH += C:\projects\emsdk\node\14.15.5_64bit\bin
PATH += C:\projects\emsdk\upstream\emscripten

Setting environment variables:
PATH = C:\projects\emsdk;C:\projects\emsdk\node\14.15.5_64bit\bin;C:\projects\emsdk\upstream\emscripten;C:\Program Files\MATLAB\R2019b\bin\win64;c:\program files (x86)\common files\honeywell_eng\dlls;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\Plantronics\Spokes3G\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Git\cmd;C:\Program Files\1E\Client\Extensibility\NomadBranch;C:\Program Files\RedHat\java-11-openjdk-11.0.5-2\bin;C:\Program Files\MATLAB\R2021a\runtime\win64;C:\Program Files\MATLAB\R2021a\bin;C:\Program Files\MATLAB\R2019b\runtime\win64;C:\Program Files\MATLAB\R2019b\bin;C:\ProgramFiles\MATLAB\R2019a\runtime\win64;C:\ProgramFiles\MATLAB\R2019a\bin;C:\Program Files\MATLAB\R2018b\runtime\win64;C:\Program Files\MATLAB\R2018b\bin;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Users\E143543\AppData\Local\Microsoft\WindowsApps;C:\Users\E143543\AppData\Roaming\npm
EMSDK = C:/projects/emsdk
EM_CONFIG = C:\projects\emsdk\.emscripten
EMSDK_NODE = C:\projects\emsdk\node\14.15.5_64bit\bin\node.exe
EMSDK_PYTHON = C:\projects\emsdk\python\3.9.2-1_64bit\python.exe
JAVA_HOME = C:\projects\emsdk\java\8.152_64bit
EM_CACHE = C:/projects/emsdk/upstream/emscripten\cache
The changes made to environment variables only apply to the currently running shell instance. Use the 'emsdk_env.bat' to re-enter this environment later, or if you'd like to permanently register this environment permanently, rerun this command with the option --permanent.
Setting the following tools as active:
node-14.15.5-64bit
python-3.9.2-1-64bit
java-8.152-64bit
releases-upstream-89202930a98fe7f9ed59b574469a9471b0bda7dd-64bit

em++.bat -Wall -std=c++1z -O0 -DMODEL=sample1 -DHAVESTDIO -DUSE_RTMODEL -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1/dist -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1 -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/include -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/src -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/${EMSCRIPTEN}/system/include -IC:/PROGRA~1/MATLAB/R2019b/extern/include -IC:/PROGRA~1/MATLAB/R2019b/simulink/include -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/ert -o "main.bc" "C:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build/main.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=sample1 -DHAVESTDIO -DUSE_RTMODEL -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1/dist -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1 -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/include -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/src -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/${EMSCRIPTEN}/system/include -IC:/PROGRA~1/MATLAB/R2019b/extern/include -IC:/PROGRA~1/MATLAB/R2019b/simulink/include -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/ert -o "_module_registered_callbacks.bc" "C:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build/_module_registered_callbacks.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=sample1 -DHAVESTDIO -DUSE_RTMODEL -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1/dist -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1 -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/include -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/src -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/${EMSCRIPTEN}/system/include -IC:/PROGRA~1/MATLAB/R2019b/extern/include -IC:/PROGRA~1/MATLAB/R2019b/simulink/include -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/ert -o "sample1_initialize.bc" "C:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build/sample1_initialize.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=sample1 -DHAVESTDIO -DUSE_RTMODEL -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1/dist -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1 -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/include -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/src -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/${EMSCRIPTEN}/system/include -IC:/PROGRA~1/MATLAB/R2019b/extern/include -IC:/PROGRA~1/MATLAB/R2019b/simulink/include -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/ert -o "sample1_terminate.bc" "C:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build/sample1_terminate.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=sample1 -DHAVESTDIO -DUSE_RTMODEL -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1/dist -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1 -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/include -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/src -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/${EMSCRIPTEN}/system/include -IC:/PROGRA~1/MATLAB/R2019b/extern/include -IC:/PROGRA~1/MATLAB/R2019b/simulink/include -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/ert -o "start.bc" "C:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build/start.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=sample1 -DHAVESTDIO -DUSE_RTMODEL -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1/dist -IC:/HONEYW~1/CONNEC~1/cGPS/Matlab/JAVASC~1/Sample1 -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/include -IC:/Users/E143543/AppData/Roaming/MATHWO~1/MATLAB~2/TOOLBO~1/GENERA~1/src -IC:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/${EMSCRIPTEN}/system/include -IC:/PROGRA~1/MATLAB/R2019b/extern/include -IC:/PROGRA~1/MATLAB/R2019b/simulink/include -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2019b/rtw/c/ert -o "render.bc" "C:/Honeywell/Connected/cGPS/Matlab/JavascriptCoder/Sample1/build/render.cpp"
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
error: undefined symbol: render (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _render may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: start (referenced by top-level compiled C/C++ code)
warning: _start may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: 'C:/projects/emsdk/node/14.15.5_64bit/bin/node.exe C:\projects\emsdk\upstream\emscripten\src\compiler.js C:\Users\E143543\AppData\Local\Temp\tmptl5r685v.txt' failed (1)
gmake: *** [main.bc] Error 1
gmake: *** Waiting for unfinished jobs....
The make command returned an error of 2

Error(s) encountered while building "sample1":
### Failed to generate all binary outputs.
------------------------------------------------------------------------
??? Build error: C++ compiler produced errors. See the Build Log for further details.
More information
Code generation failed: View Error Report
Error using codegen

Error in webcoder.internal.coder.buildProject

Error in webcoder.build.project (line 18)
webcoder.internal.coder.buildProject(proj);

>>

Greg Hacker

hmmm... I thought that I has hit SAVE on a previuos message to the one below on Windows.

I will try again.

I have a Mac and Windows PC for work. The message that I just posted a few minutes ago is for the Windows situation.

For the Mac situation:

I started with the Mac and it was working except for the error on "start" and "render" that was previously reported by myself and others.

Before I was able to see the great responses from a few people below, I tried many things and I think I messed up my environment on the Mac. Now when I run the build step, it immediatly returns with no output. So, it appears to not be doing anything.

>> emsdkRootDir = webcoder.setup.getEmscriptenRootDirectory;
Emscripten SDK root folder provided:
/Users/E143543/Desktop/emsdk
>> webcoder.setup.verifyThirdPartyTools(emsdkRootDir);
EMSDK and external tools have been verified.
>> emsdkRootDir = webcoder.setup.getEmscriptenRootDirectory;
Emscripten SDK root folder provided:
/Users/E143543/Desktop/emsdk
>> webcoder.setup.verifyThirdPartyTools(emsdkRootDir);
EMSDK and external tools have been verified.
>> webcoder.setup.saveThirdPartyToolPaths(emsdkRootDir);
Third party toolpaths saved with WebCoder.
>> webcoder.setup.createAndRegisterToolchain;
Emscripten toolchain definition created.
Emscripten toolchain registered with MATLAB Coder.
>> proj = openProject(pwd);
>> webcoder.build.project(proj);
>> webcoder.build.project(proj);
>>

Marijn Nijenhuis

Maria, yes, I ran into these issues when testing out the provided examples. Good news, though: the suggestion from Oluwasegun works! When installing emsdk 1.40.1, everything is fine. ("emsdk install 1.40.1 in command-prompt" -- pretty easy..) Thanks!

Oluwasegun Somefun

This is a very useful add-on. Unfortunately it breaks for emsdk v2.0.4 and greater.

Since webcoder.internal source-code files are obfuscated.

Users would be grateful, if either Geoff McVittie or any other MATLAB Staff ensures the bug causing this
add-on to break during build compilation for emsdk v2.0.4 and greater is treated as as soon as possible.

------------------------------------------------------------------------

The changes made to environment variables only apply to the currently running shell instance. Use the 'emsdk_env.bat' to re-enter this environment later, or if you'd like to permanently register this environment permanently, rerun this command with the option --permanent.
Setting the following tools as active:
releases-upstream-37fc7647c754ac9a28ad588c143b82286de0ef71-64bit
node-14.15.5-64bit
python-3.9.2-1-64bit
java-8.152-64bit

em++.bat -Wall -std=c++1z -O0 -DMODEL=mynewapp -IE:/SomefunAgba/Documents/MATLAB/ff/build -IE:/SomefunAgba/Documents/MATLAB/ff/dist -IE:/SomefunAgba/Documents/MATLAB/ff -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/include -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/src -IE:/SomefunAgba/Documents/MATLAB/ff/${EMSCRIPTEN}/system/include -ID:/ProgramFiles/Polyspace/R2020b/extern/include -o "main.bc" "E:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/src/main.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=mynewapp -IE:/SomefunAgba/Documents/MATLAB/ff/build -IE:/SomefunAgba/Documents/MATLAB/ff/dist -IE:/SomefunAgba/Documents/MATLAB/ff -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/include -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/src -IE:/SomefunAgba/Documents/MATLAB/ff/${EMSCRIPTEN}/system/include -ID:/ProgramFiles/Polyspace/R2020b/extern/include -o "_module_registered_callbacks.bc" "E:/SomefunAgba/Documents/MATLAB/ff/build/_module_registered_callbacks.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=mynewapp -IE:/SomefunAgba/Documents/MATLAB/ff/build -IE:/SomefunAgba/Documents/MATLAB/ff/dist -IE:/SomefunAgba/Documents/MATLAB/ff -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/include -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/src -IE:/SomefunAgba/Documents/MATLAB/ff/${EMSCRIPTEN}/system/include -ID:/ProgramFiles/Polyspace/R2020b/extern/include -o "mynewapp_data.bc" "E:/SomefunAgba/Documents/MATLAB/ff/build/mynewapp_data.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=mynewapp -IE:/SomefunAgba/Documents/MATLAB/ff/build -IE:/SomefunAgba/Documents/MATLAB/ff/dist -IE:/SomefunAgba/Documents/MATLAB/ff -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/include -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/src -IE:/SomefunAgba/Documents/MATLAB/ff/${EMSCRIPTEN}/system/include -ID:/ProgramFiles/Polyspace/R2020b/extern/include -o "mynewapp_initialize.bc" "E:/SomefunAgba/Documents/MATLAB/ff/build/mynewapp_initialize.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=mynewapp -IE:/SomefunAgba/Documents/MATLAB/ff/build -IE:/SomefunAgba/Documents/MATLAB/ff/dist -IE:/SomefunAgba/Documents/MATLAB/ff -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/include -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/src -IE:/SomefunAgba/Documents/MATLAB/ff/${EMSCRIPTEN}/system/include -ID:/ProgramFiles/Polyspace/R2020b/extern/include -o "mynewapp_terminate.bc" "E:/SomefunAgba/Documents/MATLAB/ff/build/mynewapp_terminate.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=mynewapp -IE:/SomefunAgba/Documents/MATLAB/ff/build -IE:/SomefunAgba/Documents/MATLAB/ff/dist -IE:/SomefunAgba/Documents/MATLAB/ff -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/include -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/src -IE:/SomefunAgba/Documents/MATLAB/ff/${EMSCRIPTEN}/system/include -ID:/ProgramFiles/Polyspace/R2020b/extern/include -o "start.bc" "E:/SomefunAgba/Documents/MATLAB/ff/build/start.cpp"
em++.bat -Wall -std=c++1z -O0 -DMODEL=mynewapp -IE:/SomefunAgba/Documents/MATLAB/ff/build -IE:/SomefunAgba/Documents/MATLAB/ff/dist -IE:/SomefunAgba/Documents/MATLAB/ff -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/include -IE:/SomefunAgba/Documents/MATLAB/Add-Ons/Toolboxes/Generate_JavaScript_Using_MATLAB_Coder/src -IE:/SomefunAgba/Documents/MATLAB/ff/${EMSCRIPTEN}/system/include -ID:/ProgramFiles/Polyspace/R2020b/extern/include -o "render.bc" "E:/SomefunAgba/Documents/MATLAB/ff/build/render.cpp"
shared:INFO: (Emscripten: Running sanity checks)
shared:INFO: (Emscripten: Running sanity checks)
shared:INFO: (Emscripten: Running sanity checks)
shared:INFO: (Emscripten: Running sanity checks)
shared:INFO: (Emscripten: Running sanity checks)
shared:INFO: (Emscripten: Running sanity checks)
shared:INFO: (Emscripten: Running sanity checks)
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: warning: generating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
error: undefined symbol: render (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _render may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: start (referenced by top-level compiled C/C++ code)
warning: _start may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: 'E:/SomefunAgba/Documents/MATLAB/emsdkfc/emsdk/node/14.15.5_64bit/bin/node.exe E:\SomefunAgba\Documents\MATLAB\emsdkfc\emsdk\upstream\emscripten\src\compiler.js C:\Users\SomefunAgba\AppData\Local\Temp\tmpj_qq3sp0.txt' failed (1)
gmake: *** [main.bc] Error 1
gmake: *** Waiting for unfinished jobs....
The make command returned an error of 2

Error(s) encountered while building "mynewapp"
------------------------------------------------------------------------
??? Build error: C++ compiler produced errors. See the Build Log for further details.
More information
Code generation failed: View Error Report
Error using codegen

Error in webcoder.internal.coder.buildProject

Error in webcoder.build.project (line 18)
webcoder.internal.coder.buildProject(proj);

Oluwasegun Somefun

The Changelog for emsdk v2.0.4: 09/16/2020
-----------------
- First release with Bazel support.
- Stop including `malloc` and `free` by default. If you need access to them from
JS, you must export them manually using
`-s EXPORTED_FUNCTIONS=['_malloc', ..]`.
- Stop running Binaryen optimizations in `-O1`. This makes `-O1` builds a little
larger but they compile a lot faster, which makes more sense in a "compromise"
build (in between `-O0` and higher optimization levels suitable for release
builds). (#12178)
- Add `ERROR_ON_WASM_CHANGES_AFTER_LINK` option that errors if we need to do
any work in `wasm-emscripten-finalize` or `wasm-opt` after linking. This
can verify the link is maximally fast and also does no DWARF rewriting.
(#12173)

Oluwasegun Somefun

For those having issues.

1. Install Emscripten SDK v1.40.1 or lower
2. Rename the "Generate JavaScript using MATLAB Coder" Add-On's folder to something without spaces like "GenerateJavaScriptusingMATLABCoder"
3. Ensure both the emsdk and this Add-On's folder are detected in a location that is not network mapped.
Then optionally, if all fails:
4. Ensure your Matlab Installation is in a folder without spaces. For example: instead of "C:\Program Files\", you can place it in "C:\ProgramFiles".

Maria Martinez

Hello Greg,

When I use the "assert" I do it inside a function I created and that I have added to the project. I do not put the assert on the start or render functions.

Greg Hacker

Maria or Geoff
I have the same issue that Maria had on 11 Feb 2021. She later says that I can use "assert", but in reading the info on the link, I am having toruble figuring out where exactly I put the assert for the start() and render() functions. Do i create a main.c or ???

Thank you for your help.
If you could do a youtube training video that would help this newbie and others. ;-)

Greg Hacker

Hi. Do you have any thoughts on these errors?
Thank you (I am new and still learning, so maybe something simple?)

I did the install and the check to see if things were set up. It came back as ok.

error: undefined symbol: render (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _render may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: start (referenced by top-level compiled C/C++ code)
warning: _start may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: [31merror: [0m'/Users/E143543/Desktop/emsdk/node/14.15.5_64bit/bin/node /Users/E143543/Desktop/emsdk/upstream/emscripten/src/compiler.js /var/folders/g_/vljcw4zd46v33gkw81k_w79m0000gn/T/tmpr35tizg_.txt' failed (1)
gmake: *** [main.bc] Error 1
gmake: *** Waiting for unfinished jobs....

Error(s) encountered while building "mynewapp":
### Failed to generate all binary outputs.

Maria Martinez

Hello Marijn,

Did these errors occur while testing out the examples at the documentation? It was what happened to me.

I tried to solve these changing some options of the emscripten tool but nothing seemed to work out. At the end I just created an app, as explained in the documentation, and then I cretaed a simple function that given two numbers they were added or substracted.

After that I tried to build the project using webcoder.build.project(proj) but then again it appeared errores similar to before. After going thorught the documentation once again I realized that this add-on uses Matlab Coder, I have never used this Matlab app before so I wasn't aware that the Coder needs to know the inputs of the functions you want to transcript from Matlab to C. I used the "assertive" command inside my function like explained in the Coder documentation:

https://es.mathworks.com/help/fixedpoint/ug/define-input-properties-programmatically-in-the-matlab-file.html

Then again I used webcoder.build.project(proj) and the project was build without errors. Inside the dist folder of my project it was created the result javascript of my original function. But, I had problems visualizing it on the browser, so I am not sure if at the end it worked out or not.

I hope this was of help,

María

Marijn Nijenhuis

Hello, I'm having the same issue as Maria directly below. Before the error she posted I'm seeing the warnings:
em++: [35mwarning: [0mgenerating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: [35mwarning: [0mgenerating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: [35mwarning: [0mgenerating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: [35mwarning: [0mgenerating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: [35mwarning: [0mgenerating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: [35mwarning: [0mgenerating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
em++: [35mwarning: [0mgenerating an executable with an object extension (.bc). If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]

Apparently, executables are being created instead of object files - causing the the next step to fail. Any idea how we could fix this? The toolbox looks to have very interesting functionality that I'd like to try out. Maybe emsdk has had an update in the meantime that break things with the toolbox? Should we revert to an older version of emsdk?

Maria Martinez

Hello,
I have other errors. While I am cretaing a library as following the steps in the Examples, I have the following errors:

wasm-ld: error: unknown file type: _log.bc
wasm-ld: error: unknown file type: _module_registered_callbacks.bc
wasm-ld: error: unknown file type: mylibrary_initialize.bc
wasm-ld: error: unknown file type: mylibrary_terminate.bc
wasm-ld: error: unknown file type: start.bc
wasm-ld: error: unknown file type: render.bc
wasm-ld: error: unknown file type: HelloBrowser.bc
em++: error: 'C:/Users/Usuario/Desktop/emsdk/upstream/bin\wasm-ld.exe -o ./mylibrary.wasm _log.bc _module_registered_callbacks.bc mylibrary_initialize.bc mylibrary_terminate.bc start.bc render.bc HelloBrowser.bc -LC:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libgl.a C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libal.a C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libhtml5.a C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++-noexcept.a C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++abi-noexcept.a C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libdlmalloc.a C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a C:\Users\Usuario\Desktop\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --strip-debug --export mylibrary_initialize --export start --export render --export HelloBrowser --export mylibrary_terminate --export emscripten_stack_get_end --export emscripten_stack_get_free --export emscripten_stack_init --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export fflush --export __errno_location --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (1)
gmake: *** [mylibrary.js] Error 1
The make command returned an error of 2

Error(s) encountered while building "mylibrary":
### Failed to generate all binary outputs.
------------------------------------------------------------------------
??? Build error: C++ compiler produced errors. See the Build Log for further details.

I have Matlab 2019b version. Does anyobdy know how to solve this?

Thanks.

Maria Martinez

Hi Romain, if you come across with the answer I would appreciate that you share it with me.

Thanks,

Romain Butteaud

Maria, I am in the exact same case as you now, I have reached out to the owner of this ad-on for help.

Maria Martinez

Hello,
when running the command
>> webcoder.build.project(proj);
I encounter two errors, those are:

error: undefined symbol: render (referenced by top-level compiled C/C++ code)
error: undefined symbol: start (referenced by top-level compiled C/C++ code)

I have read the comments below and it seems that I have the same problem as mamel, ecom and Fabio.I already changed the name of the directory to one without spaces and installed the Fastcomp as Chsirtopher said but neither of these helpled me with this error.

Has anyone found the solution to this?

Thanks..

Romain Butteaud

Hello,
I am getting an error when running this command (from the Setup):

>> webcoder.setup.createAndRegisterToolchain;
Unable to resolve the name coder.make.internal.generateToolchainInfoObjects.
Error in webcoder.internal.coder.getEmscriptenToolchain
Error in webcoder.internal.coder.generateToolchainFile
Error in webcoder.setup.createAndRegisterToolchain (line 10)
webcoder.internal.coder.generateToolchainFile;

Fabio Castellini

Same problem:
error: undefined symbol: render (referenced by top-level compiled C/C++ code)

Any solutions? Thanks

Geoff McVittie

@Christopher Duke - Thank you for this insight into the setting up the toolchain on the MacOS Catalina operating system. Much appreciated.

Christopher Duke

Fastcomp is no longer the default in emscripten so for anyone stuggling with getting emscripten set up correctly for version 2.02 of this toolbox on MacOS Catalina I did the following (using python 2.7.16):

git clone https://github.com/emscripten-core/emsdk.git

cd emsdk

python emsdk.py install 1.39.0-fastcomp

python emsdk.py activate 1.39.0-fastcomp

Then go through the steps outlined in setup.mlx and point it to your emsdk directory and all should be good!

ecom

hi, great tool but still not working for me.

I have the same problem as @mamel. I get stuck at >> webcoder.build.project(proj); with first error thrown:error: undefined symbol: render
I had previously error like the default directory name of the add on, changed to one without spaces and the error was gone but now I have the problem just stated;
webcoder.build.project(proj);
error: undefined symbol: render
we hope we get updated, btw nice work

mamel velasco

Great tool!
Just followed all steps. But, at compile time..... I get the next output:
>> webcoder.build.project(proj);

error: undefined symbol: render (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _render may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: start (referenced by top-level compiled C/C++ code)
warning: _start may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors

Andrew McColl

Hi Geoff,
Looks like an interesting Add-On! I'm with a group working on arbitrary distributed computing with JavaScript/Wasm, on any CPU or GPU. I'd like to have a quick chat and see if there is a way we may collaborate.
Feel free to email me at andrew@kingsds.network

Cheers,
Andrew McColl

Geoff McVittie

Hello Yoshinobu,
There is an issue with the toolchain registration in R2020a which may result in the selection of a different toolchain, e.g. MINGW, instead of the Emscripten toolchain. Can you run the Add-On in R2019b release of MATLAB to see if the issue persists?

Thank you,
Geoff McVittie

Yoshinobu Sasaki

Yoshinobu Sasaki

Hell geoff, great works!
I encountered error as foloows when executing 'webcoder.build.project(proj)' .
(OS:windows 10, MATLAB:2020a, compiler:mingw)
------------------------------------------------------------------------
"C:\PROGRA~3\MATLAB\SUPPOR~1\R2020a\3P778C~1.INS\MINGW_~1.INS\bin/g++" -c -fwrapv -m64 -std=c++11 -O0 -D__USE_MINGW_ANSI_STDIO=1 -DMODEL=mynewapp -DMODEL=mynewapp @mynewapp_rtw_comp.rsp -o "main.obj" "C:/Users/[Username]/AppData/Roaming/MathWorks/MATLABAdd-Ons/Toolboxes/GenerateJavaScriptUsingMATLABCoder/src/main.cpp"
C:/Users/[Username]/AppData/Roaming/MathWorks/MATLABAdd-Ons/Toolboxes/GenerateJavaScriptUsingMATLABCoder/src/main.cpp:3:24: fatal error: emscripten.h: No such file or directory
#include <emscripten.h>
^
compilation terminated.
gmake: *** [main.obj] Error 1
The make command returned an error of 2

"mynewapp" のビルド中にエラーが発生しました:
### Failed to generate all binary outputs.
------------------------------------------------------------------------

I already fixed MINGW's space issues, although is happens.
do you think what's wrong?
Thank you for advance.

Nicolas Hinze

I finally fixed the error. After removing the spaces in the folder you need to run the following command in MATLAB before attempting to compile again:
webcoder.setup.createAndRegisterToolchain;

Nicolas Hinze

Geoff, I changed the AddOn directory to:
C:\Users\<username>\AppData\Roaming\MathWorks\MATLABAddOns\Toolboxes\GenerateJavaScriptUsingMATLABCoder
but it still fails with the same error message.
I also messaged you through the contact link. I cannot locate an eMail address anywhere.

Geoff McVittie

Hello Nicolas,
This may be related to the same issue seen by Tom McGrath and Christian Golcic. Currently there are issues with paths containing spaces and network mapped drives that is being addressed for the next update. For the moment, please change the location of the Add-Ons directory to be on a Windows path that does not contain any spaces. You can do this by going to the MATLAB Home tab > Environment > Preferences, set MATLAB > Add-Ons > Installation Folder to a directory that does not contain any spaces; it does appear that the default folder location "C:\Users\<username>\AppData\Roaming\MathWorks\MATLAB Add-Ons" contains a space. This can be changed to "C:\Users\<username>\AppData\Roaming\MathWorks\MATLABAddOns". Please let me know if this resolves the issue. You can also reach out to me via the email included in the downloaded Add-On info available in the Add-On Manager.

Thank you,
Geoff McVittie, PhD.

Nicolas Hinze

I'm getting the following error trying to build the CreateApp on Windows 10 with R2019b 64Bit.

>> proj = webcoder.setup.project("My New App","Directory",pwd);
>> proj = openProject(pwd);
webcoder.build.project(proj);
------------------------------------------------------------------------
Adding directories to PATH:
PATH += D:\GitHub\emsdk
PATH += D:\GitHub\emsdk\node\12.18.1_64bit\bin
PATH += D:\GitHub\emsdk\python\3.7.4-pywin32_64bit
PATH += D:\GitHub\emsdk\java\8.152_64bit\bin
PATH += D:\GitHub\emsdk\upstream\emscripten

Setting environment variables:
EMSDK = D:/GitHub/emsdk
EM_CONFIG = D:\GitHub\emsdk\.emscripten
EMSDK_NODE = D:\GitHub\emsdk\node\12.18.1_64bit\bin\node.exe
EMSDK_PYTHON = D:\GitHub\emsdk\python\3.7.4-pywin32_64bit\python.exe
JAVA_HOME = D:\GitHub\emsdk\java\8.152_64bit
EM_CACHE = D:/GitHub/emsdk/upstream/emscripten\cache
Setting the following tools as active:
node-12.18.1-64bit
python-3.7.4-pywin32-64bit
java-8.152-64bit
releases-upstream-536568644fd67d53778f6111fdd5f64ad3f4c539-64bit

The changes made to environment variables only apply to the currently running shell instance. Use the 'emsdk_env.bat' to re-enter this environment later, or if you'd like to permanently register this environment globally to all users in Windows Registry, rerun this command with the option --global.
gmake: *** No rule to make target `Add-Ons/Toolboxes/Generate', needed by `_log.bc'. Stop.
The make command returned an error of 2

Error(s) encountered while building "mynewapp":
### Failed to generate all binary outputs.
------------------------------------------------------------------------
??? Build error: C++ compiler produced errors. See
the Build Log for further details.
More information
Code generation failed: View Error Report
Error using codegen

Error in webcoder.internal.coder.buildProject

Error in webcoder.build.project (line 18)
webcoder.internal.coder.buildProject(proj);

Christian Golcic

Hello,

I have the same issue as Tom McGrath below (posted 1 Jun 2020). I tried contacting you, Mr. Geoff McVittie, here on MathWorks. I cannot find your email in the downloaded Add-On.

I can be contacted in dic15cgo@student.lu.se

Thanks

Geoff McVittie

Hi Tom,
I am sorry to hear you have encountered this issue. Can you reach out to me via the email included in the downloaded Add-On? I suspect the issue may be related to the installation path, but it will almost certainly be more efficient to communicate via email.

Thank you,
Geoff McVittie

Tom McGrath

Hello Geoff!

I have completed the setup without getting any errors, but I am getting the following error when trying to build the first example app:

------------------------------------------------------------------------
gmake: *** No rule to make target `/src/console/_log.cpp', needed by `_log.obj'. Stop.
The make command returned an error of 2

Error(s) encountered while building "mynewapp":
### Failed to generate all binary outputs.
------------------------------------------------------------------------
??? Build error: C++ compiler produced errors. See the Build Log for further details.
More information
Code generation failed: View Error Report
Error using codegen

Error in webcoder.internal.coder.buildProject

Error in webcoder.build.project (line 18)
webcoder.internal.coder.buildProject(proj);

Any ideas where I might have gone with the installation?

David Fardis

Good ... I like it... Thanks ... For Formatting Javascript I used https://javascriptbeautifier.org/

Geoff McVittie

Hi Tong Lumine,
Please contact me through the contact email provided in the Add-On in the add-on manager. I will be happy to help investigate this issue you have encountered, but it will be easier to communicate via email.
Thank you,
Geoff McVittie

tong lumine

i build my project
>> proj = webcoder.setup.project("My New App");
>> webcoder.build.project(proj);
it occurs
fatal error C1083: cannot open include file : “emscripten.h"

Geoff McVittie

Some users have encountered the following error: "UnicodeDecodeError: 'ascii' codec can't decode byte ". This error results from python2.7 in the Emscripten SDK not being able to recognize non-ASCII characters in the path string on Windows. Simple Chinese characters would be example of non-ASCII characters.
As a workaround, you can install the Emscripten SDK and this Add-On into a local folder that only contains ASCII text.
Special thanks to @zhaozhouwu for discovering and reporting this issue.

Caleb Magruder

zhaozhou wu

Thank you Mr. McVittie.
I followed your advices and installed my matlab2019a on local disc and now I successfully build my first project.
Also I move the "Generate JavaScript Using MATLAB Coder" folder to the default Add-Ons folder in local disc.
I think this will help me a lot on my current design.
Great tools! I shall try to learn more.

Geoff McVittie

@zhaozhou wu
Hello,
The Add-on which includes the Toolchain registration, project folder, and most of the API requires installation on a local drive; mapped network drives will generally fail and this is a known issue. To resolve this, I would recommend the following:
(1) Install the emscripten SDK onto a local drive, C:\ should be fine.
(2) In MATLAB, set the Add-Ons folder to a folder on the local drive. You can set the Add-Ons folder in MATLAB > Home > Environment > Preferences > MATLAB > Add-Ons. If MATLAB is installed on a locally drive, the Add-Ons folder will be on the drive and may not need to be changed.
(3) Create the project in a folder on a local drive.
Try these steps and let me know if the project can be created and built successfully.
Thank you,
Geoff McVittie

zhaozhou wu

Hi,there. I have tried to install this MATLAB coder.
I installed Emscripten SDK and I set the path by following the instructions given in Setup.mlx
the following are the results:
>> emsdkRootDir = webcoder.setup.getEmscriptenRootDirectory;
Emscripten SDK root folder provided:
D:\matlab2019\emsdk-master
>> webcoder.setup.verifyThirdPartyTools(emsdkRootDir);
EMSDK and external tools have been verified.
>> webcoder.setup.saveThirdPartyToolPaths(emsdkRootDir);
Third party toolpaths saved with WebCoder.
>> webcoder.setup.createAndRegisterToolchain;
Emscripten toolchain definition created.
Emscripten toolchain registered with MATLAB Coder.

As you can see, the Emscripten toolchain is created and registered successfuly.
However, when I run the "proj = webcoder.setup.project("faceTrace");" command in the command window, error occurs as following:

错误使用 coder.internal.setToolchainOptions
'Emscripten' is not a valid Toolchain name. Use one of the following: Automatically locate an installed toolchain
AUTOSAR Adaptive | CMake
AUTOSAR Adaptive Demonstrator
Microsoft Visual C++ 2017 v15.0 | nmake (64-bit Windows)
Microsoft Visual C++ 2015 v14.0 | nmake (64-bit Windows)
LCC-win64 v2.4.1 | gmake (64-bit Windows)
MinGW64 | gmake (64-bit Windows)
NVIDIA CUDA (w/Microsoft Visual C++ 2017) | nmake (64-bit Windows)
NVIDIA CUDA (w/Microsoft Visual C++ 2015) | nmake (64-bit Windows)
NVIDIA CUDA (w/Microsoft Visual C++ 2013) | nmake (64-bit Windows)
Mentor Graphics QuestaSim/Modelsim (64-bit Linux)
Cadence Incisive (64-bit Linux)
Cadence Xcelium (64-bit Linux)
Mentor Graphics QuestaSim/Modelsim (32-bit Windows)
Mentor Graphics QuestaSim/Modelsim (64-bit Windows)
Cadence Incisive (32-bit Linux)
Catkin
IBIS-AMI Microsoft Visual C++ 2017 v15.0 | nmake (64-bit Windows)
IBIS-AMI Microsoft Visual C++ 2015 v14.0 | nmake (64-bit Windows)
IBIS-AMI Microsoft Visual C++ 2013 v12.0 | nmake (64-bit Windows)
IBIS-AMI MinGW64 | gmake (64-bit Windows)

出错 webcoder.internal.project.createProject

出错 webcoder.setup.project (line 25)
proj = webcoder.internal.project.createProject(varargin{:});

I run the commands on matlab2019a, and I didn't come across the same promble discribed by michio. So I don't think this is a problem with version.

So do I get some suggestions? I think this may be some basic mistakes since I install my matlab on disc d instead of the default location on disc c.

Pavel Roslovets

michio

Geoff McVittie

This add-on has been updated to use the Emscripten SDK version 1.39. If you are using an earlier version of the Emscripten SDK, please update to the latest version in order to use this add-on.
Special thanks to @michio for discovering and reporting this issue.

michio

This sounds like a great tool! Thanks for your hard work.

I'm trying to set-up on my Windows machine using Setup.mlx but I get an error at webcoder.setup.createAndRegisterToolchain
Here's the output:

> emsdkRootDir = webcoder.setup.getEmscriptenRootDirectory;
Emscripten SDK root folder provided:
C:\Users\minoue\emsdk-master

> webcoder.setup.verifyThirdPartyTools(emsdkRootDir);
EMSDK and external tools have been verified.

> webcoder.setup.saveThirdPartyToolPaths(emsdkRootDir);
Third party toolpaths saved with WebCoder.

> webcoder.setup.createAndRegisterToolchain;
Dot indexing is not supported for variables of this type.

Error in webcoder.internal.coder.generateToolchainFile

Error in webcoder.setup.createAndRegisterToolchain (line 10)
webcoder.internal.coder.generateToolchainFile;

Geoff McVittie

@JongWeiChew
Hello,
An updated version of the Add-On is underdevelopment that will provide easy settings of the configuration flags, including the compiler optimizations. As a work around, you can use the MATLAB coder app. In the configurations, select the "Emscripten" toolchain. You can then set and add additional compilation flags and arguments; including the compiler optimizations. Please feel free to reach out to me though the email contact information provided in the installed Add-On if you need any further help.
Thank you,
Geoff McVittie

Geoff McVittie

@LeeHwayoung
Hello,
My initial guess is that the emscripten binaries need to be recompiled for your host computer architecture AMD64, see https://emscripten.org/docs/building_from_source/index.html. Please feel free to reach out to me though the email contact information provided in the installed Add-On for help with this process.
Thank you,
Geoff McVittie

Jing Wei Chew

Hi there, please advice - is it possible to make changes to the compilation flags used by Emscripten using this add-on?

Lee Hwayoung

c:\Users\lee\Desktop\emsdk>emsdk install latest
Warning: unknown machine architecture AMD64

Error: No tool or SDK found by name 'sdk-releases-fastcomp-7b4b328af02eafbc857b8ca1e3d9b12dddc56ef7-64bit'.

Could you please advise

Silas Henderson

Geoff McVittie

⚠ For Add-On version 1.0.3 and before, on Windows, install the archived emsdk-1.12.0-full-64bit from the archived releases at the bottom of the downloads page, https://emscripten.org/docs/getting_started/downloads.html, instead of the git installation.

Geoff McVittie

@Zachery Zhu
Hello,
Can you provide more detail on the problem you had with the installation?
On Windows 10, the steps should be almost exactly as follows:

1. In Windows 10, install Emscripten
C:\Users\<user>\Desktop> git clone https://github.com/emscripten-core/emsdk.git
C:\Users\<user>\Desktop> cd emsdk
C:\Users\<user>\Desktop> emsdk install latest
C:\Users\<user>\Desktop> emsdk activate latest

2. In MATLAB, install the "GenerateJavaScriptU​singMATLABCoder" using the Add-Ons Manager.

3. In MATLAB, open the Setup.mlx by running:
>> webcoder.setup.start()

4. Follow steps 3 to 6 in Setup.mlx

Please reach out if any of the above does not work. Please include any error message that is thrown.

Thank you,
Geoff

Zachery Zhu

I still couldn't install it correctly, haha. I'm using windows 10

Geoff McVittie

@Supannee Learkthanakhachon
Thank you for the feedback. An update, v1.0.3, has corrected the typos in the examples.
Can you provide more information on the specific issues experienced in installation process? I would like to better understand and, in the future, potentially correct these issues.

Please fix the typo in the example
>> server = webcoder.utilities.DeploymentServer("Port",8000)
it should be
>>server = webcoder.utilities.DevelopmentServer("Port",8000)
I spent a long time to figure this out. Plus...the entire installation process was a headache.

Larry Kyrala

Larry Kyrala

On Mac OSX, emscripten setup is done with bash scripts, so webcoder.setup.verifyThirdPartyTools failed with an error "BASH_SOURCE Undefined variable". You'll want to set MATLAB's shell to bash using something like: export MATLAB_SHELL=`which bash` before you verify.

MATLAB Release Compatibility
Created with R2019b
Compatible with R2019a to R2019b
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!