VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Compiling a Veristand dll from Simulink Model: file relative path

Solved!
Go to solution

Can you please show me how to setup relative build paths in Simulink using the VeriStand builder or confirm to me that it is impossible to do so using the 2015 SP1 version ?

 

I have a Simulink project that builds correctly into a DLL that can be imported as a model in VeriStand -see attached Simulink project, configuration is VeriStand 2015 SP1, Matlab 2015b, Windows SDK 7.1.

 

In order to build the project :

- 1.Execute Zeke.m to build the s-function

- 2.Open Z_model.slx and build (Ctrl+B)

 

Now what I want to do is put the *.h files and the *.c files respectively in two folders called "include" and "source".

 

In order to make this work, Zeke.m needs to be modified to reflect the path changes, this step works and then the s-function from step 1. can be created normaly.

Then when launching a model build, step 2. the compiler throws an error saying that the *.h files cannot be found.

 

I have tried any combination of settings in the Model properties under Custom code for the file paths but the VeriStand builder seems to not even use these fields.

0 Kudos
Message 1 of 4
(3,723 Views)

I followed the advice given in this documentation page : http://zone.ni.com/reference/en-XX/help/372846G-01/veristand/convert_model_to_dll/

 

At first, I couldn't find the Real-Time Workshop menu described in this page. After some investigation, I found that this menu used to exist in previous versions versions of the program. (see http://users.isr.ist.utl.pt/~alex/micd0506/rtw.pdf page 30).

 

The modern equivalent of the incriminated parameters is under "Configuration Parameters > Simulation Target > Custom Code" which is what I've been fiddling with to no success so far. Just to make sure, I tried again the following syntaxes in the "Header file" text box without it working:

   #include "Z_f.h"

   #include "include/Z_f.h"

   #include "include\Z_f.h"

Same error with "Include directories" filled with the path to the "include" directory.

   'C:\Users\User1\Documents\MATLAB\Global\include'

 

I joined a new version of the mini-project to reproduce the problem.

   - One missing file added

   - Irrelevant comments removed

   - Added empty "include" and "source" folders

Follow the same steps as decribed in my first post to reproduce the problem.

0 Kudos
Message 2 of 4
(3,670 Views)

Further investigation.

Here is the file tree of the mini-project I attached (Folder named "0"):
./include/useless.h
./include/Z_f.h
./include/Z_legf.h
./source/Z_f.c
./source/Z_legf.c
./Zeke.m
./Z_model.slx

The first step is to build the s-function code for the legacy_code block. I execute Zeke.m and 3 new files are created:
./sfun_legf.c
./sfun_legf.mex64
./sfun_legf.tlc

The second step is to build the DLL from the model. I enter Z_model.slx and press Ctrl+B. The build fails, but new folders are created (Find associated files and build log under folder named "1"):
./slprj/
./Z_model_niVeriStand_rtw/

Specifically, the linker fails under the following error :
./Z_model_niVeriStand_rtw/Z_model.h(28) : fatal error C1083: Cannot open include file: 'Z_legf.h': Invalid argument

Now if I open the incriminated file I see that it is indeed impossible for the file to find the header because it is in another folder.
#include "Z_legf.h"
Should be instead
#include "../include/Z_legf.h"

Modiying this file is useless because it is generated from the building step. By investigating further it appears that these lines written from the instructions in /sfun_legf.tlc, that were generated in the first step.

My next test was to change lines 33 to 35 of /sfun_legf.tlc after the first build step so that it contains
#include "../include/Z_legf.h"
#include "../include/Z_f.h"
#include "../include/Z_useless.h"
instead of
#include "Z_legf.h"
#include "Z_f.h"
#include "Z_useless.h"

This bypasses the first error we got, but now the 2nd step of the build fails under the following error message :
LINK : fatal error LNK1181: cannot open input file 'Z_f.obj'
At which point I have no idea how to fix the problem upstream. (Find associated files and build log under folder named "2")

To go one step further up would be modifying ./Zeke.m so that it directly mentions "../include/Z_legf.h" in def.IncPaths but the legacy_code tool only accepts file name without path in this field.

Notice that at not any moment the parameters from the model configuration parameters are taken into acount, the fields under "Custom code" just seem to have no effet at all on the build (this is recommanded here http://zone.ni.com/reference/en-XX/help/372846G-01/veristand/convert_model_to_dll/). Maybe the compatibility was broken when the new version of Simulink Coder (former Real Time Workshop) was released. The problem boild down to the include path parameters set in Zeke.m for the legacy_code function not being passed down correctly to NIVeriStand.tlc so unless there is a parameter that has escaped my attention so far, I don't think the integration of a file tree is compatible with the DLL builder.

0 Kudos
Message 3 of 4
(3,660 Views)
Solution
Accepted by topic author FranckYin

The issue wasn't on VeriStand's side at all for the whole time.

I added a command at the end of my legacy_code generation script and the build was succesful :

legacy_code('rtwmakecfg_generate', def)

This creates a rtwmakecfg.m script that help the model builder to find the files.

Message 4 of 4
(3,635 Views)