Using Local Source for Remote Programming in CLion


Local Client Operating System: macOS / Linux / Windows
Remote Host Operating System: Linux
Source File Location: Local, automatically synchronized to remote host
Required Tools on Remote Host: macOS/Linux/Windows client needs rsync, Windows client needs tar
Project Model: CMake/Makefile
Required Plugins (pre-installed and enabled by default): FTP/SFTP/WebDAV connection
This remote mode allows you to use CLion for development targeting a remote Linux machine from your macOS, Linux, or Windows desktop via SSH. You can choose any Linux-based target system, including embedded systems on single-board computers like Raspberry Pi, or run your programs in cloud platforms or Docker containers.
In this mode, the IDE instance runs locally, and the source files are also placed on the local client and automatically synchronized to the remote host. On the remote host, CLion uses the host's compiler and CMake/make for compilation and building, uses the host's GDB for debugging, and runs applications on the remote target.

👇Click to receive👇
👉C Language Knowledge Resource Collection

Workflow Steps to Create a Remote Toolchain with CMake:
  • Provide credentials and check the connection,

  • Wait for tool detection, provide paths manually if necessary.

  • Set the remote toolchain as default or create an associated CMake configuration file.

  • Adjust path mappings in the deployment entries if needed.

  • Build, run, and debug using the default configuration file or select a configuration file from step 2.

  • Makefile

    1. Create a remote toolchain:

    • Provide credentials and check the connection,

    • Wait for tool detection, provide paths manually if necessary.

  • Switch to the remote toolchain in Settings | Build, Execution, Deployment | Makefile.

  • Adjust path mappings in the deployment entries if needed.

  • Call Tools | Makefile | Clean and Reload Makefile Project.

    Point the executable to the remote binary in configuration settings.

  • Special Notes for Windows Clients

    When using the Windows client, please note the following:

    • Due to IntelliJ platform issues, you need to set the property value idea.case.sensitive.fs=true in the idea.properties file (access the properties file via Help | Edit Custom Properties… in the main menu), then restart CLion with cache reset.

    • On Windows, by default, CLion relies on its own Remote Host Access and the host side’s tar tool for file synchronization. This synchronization mechanism is slower than the Rsync tool on macOS and Linux. You can enable Rsync synchronization on Windows by selecting the Use Rsync for download/upload/sync checkbox in the deployment settings.

    Create Toolchain with Remote Credentials

    1. Go to Settings | Build, Execution, Deployment | Toolchains.

    2. Click Using Local Source for Remote Programming in CLion and select Remote Host:

      Using Local Source for Remote Programming in CLion

      If you already have an SSH configuration, select it from the credentials list:

      Using Local Source for Remote Programming in CLion

      Otherwise, click on the credentials field next to Using Local Source for Remote Programming in CLion. In the opened dialog, create an SSH configuration and provide access credentials for the remote machine:

      Using Local Source for Remote Programming in CLion

      Once the connection is established, CLion attempts to detect tools at the default remote locations /usr/bin/cmake and /usr/bin/gdb (if you provided the full path manually, these paths will be used). Once the checks are successfully completed, the toolchain will be available:

      Using Local Source for Remote Programming in CLion

      You can set the newly created toolchain as default (to do this, click Using Local Source for Remote Programming in CLionUsing Local Source for Remote Programming in CLion to move it to the top of the toolchain list). Once set as default, the remote toolchain will be used for all projects you create and open in CLion.

    (CMake) Create Corresponding CMake Configuration File

    • Go to Settings | Build, Execution, Deployment | CMake.

    • Click Using Local Source for Remote Programming in CLion to create a new CMake configuration file and link it to your remote toolchain using the toolchain field:

      Using Local Source for Remote Programming in CLion

    • Alternatively, set the remote toolchain as default and choose to use the default values.

    • Apply changes.

    (Makefile) Select Remote Toolchain in Makefile Settings

    1. Go to Settings | Build, Execution, Deployment | Makefile.

    2. Select your remote toolchain in the toolchain field:

      Using Local Source for Remote Programming in CLion

    3. Alternatively, set the remote toolchain as default and choose to use the default values.

    4. Apply changes.

    5. Use the File Transfer Tool Window (View | Tool Windows | File Transfer) to monitor file synchronization progress:

      Using Local Source for Remote Programming in CLion

    Check and Adjust Deployment Configuration

    When you create a connection entity for the remote toolchain, CLion places it in the server access configuration list under Settings | Build, Execution, Deployment | Deployment.

    • CLion automatically configures your project code synchronization paths. Use the mapping tab to change the default mapping (for example, set the copied source to a specific remote directory outside the default tmp folder):

      Using Local Source for Remote Programming in CLion

      CMake

      For CMake projects, CLion automatically triggers synchronization when you change deployment settings. You can monitor the process in the File Transfer Tool Window (View | Tool Windows | File Transfer):

      Using Local Source for Remote Programming in CLion

      When you upload a project to the remote machine, CLion uses the directory containing the top-level CMakeLists.txt as the project root (CPP-23995). If your top-level CMakeLists.txt is in a different subdirectory, change the local path in the mapping tab.

      Makefile

    • When uploading Makefile projects to the remote machine, CLion uses the directory containing the Makefile as the project root. If your Makefile is in a different subdirectory, change the local path in the mapping tab.

    • You can set up remote development without source code synchronization to avoid unnecessary file duplication when sharing mounted volumes between local and remote machines (for example, when using Docker containers) or when third-party synchronization is configured outside of CLion.

      To do this, open the connection tab and change the connection type to local or mounted folder, then set the path mappings (for Docker, specify the mapped volume).

      Using Local Source for Remote Programming in CLion

      CLion always downloads CMake build folders when reloading CMake. However, if the local or mounted folder deployment type is selected, and the CMake build folder is stored under the existing path mapping, this action can be skipped.

    • The deployment process of SFTP connections can be accelerated by the Rsync tool. On macOS and Linux, Rsync support is enabled by default, while on Windows, you need to enable it by selecting the Use Rsync for download/upload/sync checkbox in the deployment settings.

    Exclude Paths

    By default, CLion indexes and synchronizes all directories listed in CMakeLists.txt. However, if you mark a directory for exclusion using the | Exclude operation, it will be marked as an excluded path for remote deployment and will not be synchronized with the remote machine. CLion will automatically perform this operation when you configure the remote toolchain and have synchronized the project.

    You can check and adjust the excluded paths in the dedicated tab of the deployment entry settings:

    Using Local Source for Remote Programming in CLion

    • If you mark a directory for exclusion after configuring the remote toolchain and the project has been synchronized, CLion will suggest that you update the excluded paths. After updating, the excluded folder will no longer be synchronized.

      Using Local Source for Remote Programming in CLion

    • If you cancel the exclusion of a previously excluded directory, CLion will suggest updating the excluded paths list and re-uploading the folder to the remote host.

      Using Local Source for Remote Programming in CLion

    Resync Header File Search Paths

    To correctly resolve your code, CLion synchronizes all header file search paths on the remote machine with the local client. For example, even if the standard library header files come from the target, you can navigate to them as if you were working locally in the CLion editor.

    However, synchronizing header file search paths can be very time-consuming, so CLion only performs it automatically during the initial file transfer. After that, it will not trigger due to CMake or Makefile reloads. Therefore, whenever you switch compilers or change project dependencies, make sure to manually update the header file search paths by calling Tools | Resync Remote Host.

    Note

    Each time you make changes to project dependencies or the compiler, you need to manually call Resync Remote Host.

    You can also switch to automatic synchronization: set the clion.remote.resync.system.cache key in the registry (go to Help | Find Action or press CtrlShiftA, type Registry, and search for the key by name).

    Starting from version 2022.3, CLion uses pigz (a multi-threaded gzip implementation) for compression on the remote host to sync header file search paths back to the local host, replacing gzip. This speeds up the synchronization process.

    Build, Run, Debug

    CMake

    Now that you have configured the remote toolchain and the corresponding CMake configuration file, you can build, run, and debug your applications and tests in a fully remote manner by selecting the correct CMake configuration file:

    Using Local Source for Remote Programming in CLion

    Here is a demonstration showing how the application output varies depending on the operating system it runs on. Using macOS as the local system, we connect remotely to an Ubuntu target and check the operating system name. In this example, the code highlighting depends on the operating system identifier, so when we switch CMake configuration files or resolve contexts, CLion highlights the corresponding code branch:

    Using Local Source for Remote Programming in CLion

    Makefile

    1. Create a new Native Application configuration or edit an existing one.

    2. In the Executable field, point to the remote binary file of CLion.

      Tip

      To quickly find the path to the project directory on the remote host, call Tools | Open Remote Host Terminal.

      Using Local Source for Remote Programming in CLion

      Save the configuration and use it to run or debug your Makefile application remotely.

    Tip

    For CMake and Makefile configurations, you can set remote external tools as pre-launch steps.

    Set Environment Variables

    To configure environment variables for the remote operating system, specify them at the beginning of the .bashrc file, before the line # If not running interactively, don’t do anything.

    If your main shell is not bash, follow the guide for that specific shell, or add PermitUserEnvironment yes to the sshd_config file in ~/.ssh/environment, restart the sshd service, and then configure the variables.

    Enable IPv6 Support

    • To connect to an IPv6 network, you need to make adjustments in the CLion JVM options:

    1. Run Help | Edit Custom VM Options from the main menu. In the opened *.vmoptions file, delete the line -Djava.net.preferIPv4Stack=true and add the following lines:

      -Djava.net.preferIPv4Stack=false
      -Djava.net.preferIPv6Stack=true
      -Djava.net.preferIPv6Addresses=true
    2. Restart CLion.

  • To use hostnames instead of raw addresses, open C:\Windows\System32\Drivers\etc\hosts as an administrator on Windows, and open /etc/hosts as a superuser on macOS/Linux, mapping the desired addresses to the corresponding hostnames.

    Each address should be on a separate line, followed by at least one space and a series of space-separated hostnames, for example:

    f381::171d:c61c:c7f3:3a56      my.dev.host1 my.dev.host2
    f381::171d:c61c:c7f3:3a26%en0  my.dev.host3
  • On macOS, you also need to specify a list of disabled network interfaces:

    1. Press CtrlShiftA or select Help | Find Action from the main menu. Start typing Registry in the opened popup and select the corresponding item and press Enter.

    2. Find the deployment.macOs.bannedInterfaces key and set a comma-separated list of interfaces to disable, e.g., awdl0,bridge0,en1,en2,lo0,p2p0,utun0,utun1.

    
    Popular Recommendations
    
    • Ridiculous operation, investigated by the previous company after resignation…

    • Revealed! Why HR prefers one-page resumes?

    • Little group turns into “little prisoner”, voice pack down to countdown…

    Leave a Comment