CLion 2024.2 Help

Path variables

Use path variables to define absolute paths to resources that are not part of a specific project. These external resources may be located in different places on the computers of your teammates. This is why user-defined custom path variables are not stored as project settings, but as global IDE settings. Once configured, such path variables will have the same value for any project that you open with your instance of CLion.

There are two pre-defined variables in CLion: $USER_HOME$ for your home directory and $PROJECT_DIR$ for the directory where your project is stored.

You can refer to path variables when configuring external tools and run/debug configurations of the following types:

Create and use a path variable

For example, when your program takes input data from a file, you can create a path variable for the file location, and then refer to this variable in a run/debug configuration that you share through VCS with your teammates.

  1. Press Ctrl+Alt+S to open settings and then select Appearance & Behavior | Path Variables.

  2. Click the Add button and enter the name of the new variable (for example, DATA_PATH) and its value that points to the target directory with the data file on your disk:

    Creating a new path variable
  3. In the configuration settings, click the Add button in the required field (Redirect Input in our example). Select the variable in the Macros dialog:

    Using a path variable in configurations
  4. Set the Store as project file checkbox and specify the location where the file with your configuration will be stored:

    Saving a configuration into a file
  5. You can check the contents of this file (which is <project directory>.idea/runConfiguration/<configuration name>.xml by default):

    Path variable in the .xml file for a configuration
  6. Now if you share this .xml file through VCS, your teammates will get the configuration with $DATA_PATH$ in it, and they will be able to change the value so that it points to their location of the input data file.

Ignore path variables

Whenever you open or update a project, CLion checks for unresolved path variables. If the IDE detects any, it will ask you to define values for them. If you are not going to use files or directories with the unresolved path variables, you can add them to the list of ignored variables.

You can also use the list of ignored variables when a program argument passed to the run/debug configuration has the same format as a path variable (for example, an environment variable).

  1. Press Ctrl+Alt+S to open settings and then select Appearance & Behavior | Path Variables.

  2. Add the names that CLion shouldn't consider to be path variables to the Ignored Variables field.

  3. Click OK to apply the changes.

Last modified: 08 October 2024