Search code examples
c++visual-studio-coderemote-debugging

VS code C++ code runner setup in remote server


Hello I am trying to setup VS code code runner setup in a remote server so that I can use the VS code debugger. Usually when I run code from the terminal, I have to at first load the g++ module. My usual c++ compile and run sequence goes as:

module load Compilers/gcc-4.9.2
g++ -o test test.cpp
./test

Now after installing code runner, if I try to run it in vs code by clicking the run button, I get the following error:

[Running] cd "/data/<server_name>/users/<username>/" && g++ practice.cpp -o practice && "/data/<server_name>/users/<username>/"test
/bin/sh: g++: command not found

How should I setup my VS code to run cpp files and use the debugger feature in this remote server? I use VS Code remote development successfully in my setup as well. Thanks a lot!


Solution

  • In your Visual Studio Code UI below right, you'll find the possibility to call the setting for your workspace:

    enter image description here

    You should be able to update your setting to find the installed compiler in your remote system. The JSON setting looks like this:

    {
        "configurations": [
            {
                "name": "Linux",
                "includePath": [
                    "${workspaceFolder}/**"
                ],
                "defines": [],
                "compilerPath": "/usr/bin/gcc",
                "cStandard": "gnu11",
                "cppStandard": "gnu++14",
                "intelliSenseMode": "clang-x64"
            }
        ],
        "version": 4
    }
    

    It is also possible to set it using the UI. For more details, you could also check the official site.