Code Archive (.ctf
file) Placement
With the MATLAB Data API, providing a MATLAB® function or class to the compiler.build.cppSharedLibrary function or
the 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_PATH
environment variable to point to the directory containing the code archive (.ctf
file). This can be done within the MATLAB command prompt using thesetenv
function, or at the system command prompt—utilizingexport
on Linux® andset
orsetx
on 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 (
.ctf
file)Alternatively, copy or move the code archive (
.ctf
file) directly into the location of the C++ executable.Switch to directory containing the code archive (
.ctf
file).Navigate to the directory containing the code archive (
.ctf
file) and execute the C++ application from this location. For instance, if your code archive (.ctf
file) is located atP:\MATLAB\work\output\v2\generic_interface
and 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