Main Content

Code Archive (.ctf file) Placement

With the MATLAB Data API, providing a MATLAB function or class to the 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:

  1. 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 the setenv function, or at the system command prompt—utilizing export on Linux® and set or setx on Windows®. If you're using Visual Studio®, see Setting Environment Variable 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:


    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"
  2. 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.

  3. 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 at P:\MATLAB\work\output\v2\generic_interface and your C++ executable resides in P:\MATLAB\work\CalculateDistance\x64\Debug, you would navigate to the directory containing the code archive and execute the C++ application as follows:


Related Topics