MATLAB: Is it possible to use the C caller block with third-party libraries

arduinoblockccallercodegenerationlibrariessimulink coderthird-party

Best Answer

The Unknown Exception error which is shown during the build process is due to an issue when Simulink is parsing the custom C file. Simulink is not able to parse the source file effectively because the files related to the third-party methods are not used during parsing.
If the goal is to generate code for the function defined in the source file, please perform the following steps:
  1. Check the “Use the same custom code settings as Simulation Target” option in “Custom Code” section of Code generation and uncheck the “Import custom code” in Simulation target section.
  2. Create a Function Caller and give the same function prototype as defined in the source or header file.
  3. Connect an inport, gain block and an outport (This is only done for the purpose of generating code and not optimizing out everything.)
  4. Check the “Generate Code only” option.
  5. Generate code.
The generated code will contain all of the necessary include and source files.
The generated code will build successfully given that all the libraries and required include files are present. Simulink will not perform any checks related to this during the build process therefore it is in the hands of the user to ensure that everything is linked properly. If it is not, the build process will produce an error.