MATLAB Answers

What is the correct way to specify directory path in the LibSetSour​ceFileOutp​utDirector​y TLC function?

7 views (last 30 days)
I want Real-Time Workshop to generate *.c and *.h files into a custom directory rather than into the default build directory. So I specify the following commands in my custom templates TLC file for the model:
%assign pubName = LibGetMdlPubHdrBaseName()
%assign modelH = LibCreateSourceFile("Header", "Simulink", pubName)
%<LibSetSourceFileOutputDirectory(modelH, "C:\Work\Build")>
I, however, receive an error message when trying to generate code from the model. A snippet of the error message is provided below:
Error: File: Y:\R2008a\matlab\rtw\c\tlc\mw\ertsourcetemplate.tlc Line: 110 Column: 30
Unable to open output file C:WorkBuild\oa_cyclic_class_header_creation.h
I would like to know the correct format for specifying the directory path.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 Nov 2009
The behavior observed is because the directory is interpreted as "C:WorkBuild" instead of "C:\Work\Build". To match a character that is a special metacharacter, regexp escapes that character with a '\'. So you need to use two backslashes whenever you need one backslash, for example, "C:\\Work\\Build". The first backslash escape makes sure that the second backslash is not interpreted as a special metacharater.
  1 Comment
Juan Reyes
Juan Reyes on 7 Jun 2016
Thanks for your answer! Just to expand.
Here is my full working syntax for a new "model_data.h" file under Linux OS
%assign mdlName = LibGetModelName()
%assign fileName = "%<mdlName>_data"
%assign hFile = LibCreateSourceFile("Header", "Custom", "%<fileName>")
%assign tag = LibSetSourceFileOutputDirectory(hFile,"//Your//Desired//Absolute//Path")

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!