How to include all required headers in code generated by MATLAB coder?

9 views (last 30 days)
I'm generating C++ source code from MATLAB with Coder.
Some of my functions require cs.h: #include "cs.h" but MATLAB does not automatically include the "cs.h" header file in the generated files. I can find the file from ${MATLAB_ROOT_DIR}/toolbox/eml/externalDependency/CXSparse/Include, but I do not want to manually search for the file and include it. I later manually compile the generated C++ and at the moment, I have to manually find the "cs.h" file and configure it to the build. I do not want to do this everytime I get a new dependency.
I would like to have all the headers and sources that the generated C++ code needs automatically in the generated codegen folder. Is this possible?
  2 Comments
Hein Gustavsen
Hein Gustavsen on 9 Nov 2022
We have the same problem with MATLAB R2022b update 1 and MATLAB Coder 5.5. Files are generated correctly, but The files from CXSparse and CXSparseHelper are not copied to output. Work-around is to manually coping the files from those folders.

Sign in to comment.

Answers (1)

Ryan Livingston
Ryan Livingston on 9 Nov 2022
Edited: Ryan Livingston on 9 Nov 2022
When I run the codegen command in MATLAB Coder in MATLAB R2022b, I see that all CXSparse files appear in the codegen folder under CXSparse:
>> !tree codegen/lib/f/CXSparse/
codegen/lib/f/CXSparse/
├── CXSparseSupport
│   ├── coder_cs.h
│   ├── makeCXSparseMatrix.c
│   ├── makeCXSparseMatrix.h
│   ├── solve_from_lu.c
│   ├── solve_from_lu.h
│   ├── solve_from_qr.c
│   ├── solve_from_qr.h
│   ├── unpackCXStruct.c
│   └── unpackCXStruct.h
├── Include
│   └── cs.h
├── License
│   ├── ChangeLog
│   ├── lesser.txt
│   └── License.txt
├── Source
│   ├── cs_ci_bundle.c
│   └── cs_ri_bundle.c
└── SuiteSparse_config
├── Makefile
├── README.txt
├── SuiteSparse_config.c
├── SuiteSparse_config.h
└── SuiteSparse_config.mk
5 directories, 20 files
I verified that this list is complete by zipping up the folder and building the generated code on another machine. If you see other behavior with MATLAB Coder, can you please share reproduction steps with technical support so we could investigate?
As Denis mentioned, in general the best practice to package the generated code and all dependencies is by using one of the following:
  • The MATLAB function packNGo: packNGo('/some/folder/codegen/lib/foo')
  • The package argument to codegen: codegen foo.m -package fooPackage.zip
  • The package button in the MATLAB Coder App and report
Those will give you a ZIP file with all dependencies included that can be relocated.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!