Code Archive (.ctf file) Placement
With the MATLAB Data API, providing a MATLAB® function or class to the
compiler.build.cppSharedLibrary function or the C++ Shared
Library Compiler app results in the generation of a code archive
(.ctf file) and a header (.hpp
file).
The header file (.hpp) needs to be incorporated into your C++
application code, and the code archive (.ctf file), which serves
as input to either the matlab::cpplib::initMATLABLibrary or
matlab::cpplib::initMATLABLibraryAsync C++ API functions,
must be situated in a location accessible to the C++ executable. You have the
following options for the placement of the code archive (.ctf
file):
To ensure your C++ application can access the code archive
(.ctf file) containing MATLAB code, place the file in a location accessible to the executable. Here
are two quick methods:
Set an environment variable
Set the
CPPSHARED_BASE_CTF_PATHenvironment variable to point to the directory containing the code archive (.ctffile). This can be done within the MATLAB command prompt using thesetenvfunction, or at the system command prompt—utilizingexporton Linux® andsetorsetxon Windows®. If you're using Visual Studio®, see Set Environment Variables in Visual Studio. The options for setting the environment variable in different environment are:For this example, set the environment variable from the MATLAB command prompt:
setenv("CPPSHARED_BASE_CTF_PATH","P:\MATLAB\work\output\v2\generic_interface")
MATLAB setenv("CPPSHARED_BASE_CTF_PATH","\path\to\your\codearchive\directory")
Linux Terminal export CPPSHARED_BASE_CTF_PATH="/path/to/your/codearchive/directory"
Windows Command Prompt Current Command Prompt session:
set CPPSHARED_BASE_CTF_PATH=\path\to\your\codearchive\directory
Future Command Prompt windows:
setx CPPSHARED_BASE_CTF_PATH "\path\to\your\codearchive\directory"
Windows PowerShell $env:CPPSHARED_BASE_CTF_PATH = "\path\to\your\codearchive\directory"
Copy or move the code archive (
.ctffile)Alternatively, copy or move the code archive (
.ctffile) directly into the location of the C++ executable.Switch to directory containing the code archive (
.ctffile).Navigate to the directory containing the code archive (
.ctffile) and execute the C++ application from this location. For instance, if your code archive (.ctffile) is located atP:\MATLAB\work\output\v2\generic_interfaceand your C++ executable resides inP:\MATLAB\work\CalculateDistance\x64\Debug, you would navigate to the directory containing the code archive and execute the C++ application as follows:P:\MATLAB\work\output\v2\generic_interface>P:\MATLAB\work\CalculateDistance\x64\Debug\CalculateDistance.exe