Simulink Coder, add external C++ libraries placed outside the working directory

13 ビュー (過去 30 日間)
Marcell
Marcell 2016 年 2 月 10 日
編集済み: Marcell 2016 年 2 月 22 日
Following problem: I'm using Simulink Coder, an Arduino Due and a self developed expansion board to control multicopters. I've a Simulink model with all the device drivers (made with s-function builder) to interact with the sensors. Every sensor has an own c++ library which is included in the s-function. All the c++ and header files are currently in the working directory of matlab.
No I have so many device driver blocks, that I made a custom Simulink block library in order to share and use these blocks in multiple Simulink models. However, if I'm using the blocks from my Simulink library the compiler gives an error because it can't find the c++ and header files, as they are not in the current working directory but in the directory of the Simulink library. However the Simulink block library and all the external c++ libraries are included in the Matlab search path (set path).
So does anyone know how to include external c++ libraries when they are called from an s-function in a Simulink block library?
I already tried following steps:
-I tried to include the c++ and header files with following matlab command (doesn't work): set_param('SimulinkModelName','CustomSource',"LibraryName");
-Copy the c++ and header files to the directory of the c++ libraries of the Arduino Simulink support package (doesn't work).
-Copy all the c++ and header files into the directory of the current Simulink model (does work however I don't want to copy all the files every time a new simulink model is created) Does anyone had similar problems so far?

回答 (2 件)

Philipp Schaefer
Philipp Schaefer 2016 年 2 月 20 日
They include it with a S-function that has no input, and no output. Run renc2cpp('sfcn_include_name') after that. (Read explanation in simulink file for more information)

Marcell
Marcell 2016 年 2 月 22 日
編集済み: Marcell 2016 年 2 月 22 日
Thank you for your answer. You pointed me in the right direction.
The problem is, that for code generation MATLAB calls the C-compiler, which knows nothing about the MATLAB path. So if the custom libraries are not in the current working path, the compiler can’t find them. After a little research i found following solutions:
Include the custom library with model-wide parameters:
set_param(model, 'CustomSource', [source.cpp’ ‘ source2.cpp’ ‘ ’ ’sourceN.cpp]);
This needs to be done for every Simulink model so its not perfect for sharing it with other users.
The right way to do this is to create a rtwmakecfg.m file and place it into the folder of the library. Inside the rtwmakecfg.m file the path to the custom source and header files can be specified. This will ensure, that any model which uses my s-function blocks will link against the required custom libraries.
Link with the solution:

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by