Skip to content

Instantly share code, notes, and snippets.

@somefunAgba
Created May 6, 2021 18:41
Show Gist options
  • Save somefunAgba/744e8ef7462b8f1efc976cf7b9efaa57 to your computer and use it in GitHub Desktop.
Save somefunAgba/744e8ef7462b8f1efc976cf7b9efaa57 to your computer and use it in GitHub Desktop.
matlab: missing emxAPI header file during webcoder's build compilation (Generate Javascript Using Matlab Toolbox)
%% 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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment