microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.47k stars 454 forks source link

environment PATH in `settings.json` `launch.json` not effect #3324

Open WittonBell opened 1 year ago

WittonBell commented 1 year ago

reproduce step

  1. remove all PATH about MinGW from SYSTEM PATH environment var, only use environment PATH in cmake configuration.
  2. copy gdb.exe only to a separate directory, such as G:/msys64/opt/t/.
  3. set VSCode default terminal is Command Prompt.
  4. create a cmake project t.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.26)
project(t)
add_executable(t t.cpp)

t.cpp:

#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    cout << "Hello, CMake" << endl;
    return 0;
}

CMakePresets.json:

{
  "version": 3,
  "configurePresets": [
    {
      "name": "gcc-base",
      "hidden": true,
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build",
      "installDir": "${sourceDir}/install",
      "environment": {
        "MSYS2_ROOT": "G:/msys64",
        "MINGW64_ROOT": "$env{MSYS2_ROOT}/mingw64",
        "PATH": "$env{MINGW64_ROOT}/bin;$env{MSYS2_ROOT}/usr/bin;$penv{path}",
        "BIN_ROOT": "$env{MINGW64_ROOT}/bin",
        "FLAVOR": "x86_64-w64-mingw32",
        "TOOLSET_VERSION": "13.2.0",
        "INCLUDE": "$env{MINGW64_ROOT}/include;$env{MINGW64_ROOT}/lib/gcc/$env{FLAVOR}/$env{TOOLSET_VERSION}/include",
        "environment": "mingw_64"
      },
      "cacheVariables": {
        "CMAKE_C_COMPILER": "gcc.exe",
        "CMAKE_CXX_COMPILER": "g++.exe"
      },
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
      },
      "vendor": {
        "microsoft.com/VisualStudioSettings/CMake/1.0": {
          "intelliSenseMode": "linux-gcc-x64",
          "intelliSenseOptions": {
            "useCompilerDefaults": true
          }
        }
      }
    },
    {
      "name": "gcc-debug",
      "displayName": "gcc Debug",
      "inherits": "gcc-base",
      "architecture": {
        "value": "x64",
        "strategy": "external"
      },
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug"
      }
    }
  ]
}

.vscode/settings.json

{
  "cmake.debugConfig": {
    "MIMode": "gdb",
    "miDebuggerPath": "G:/msys64/opt/t/gdb.exe",
    "args": [],
    "stopAtEntry": false,
    "externalConsole": true,
    "cwd": "${workspaceFolder}",
    "environment": [
      {
        "name": "PATH",
        "value": "G:/msys64/mingw64/bin/;G:/msys64/opt/t/;$penv{path}"
      }
    ]
  }
}

.vscode/launch.json

{
    "configurations": [
    {
        "name": "(gdb) start",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/build/t.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [
            {
                "name": "PATH",
                "value": "G:/msys64/mingw64/bin/;G:/msys64/opt/t/;$penv{path}"
            }
        ],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "G:/msys64/opt/t/gdb.exe",
        "setupCommands": [
            {
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            },
            {
                "text": "-gdb-set disassembly-flavor intel",
                "ignoreFailures": true
            }
        ]
    }
    ]
}
  1. press VSCode cmake debug button from status bar, cannot start debugging, output:

    [proc] run command: G:/msys64/opt/t/gdb.exe --version
    [proc] command “G:/msys64/opt/t/gdb.exe --version” exited,code is 3221225781
    [proc] run command: gdb --version
    [proc] command“gdb --version”exited,code is 1
  2. press (gdb) start button from run and debug pannel, cannot start debugging, and then it got stuck, output:

    cmd /C "c:\Users\Admin\.vscode\extensions\ms-vscode.cpptools-1.17.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-l44q34gi.smx --stdout=Microsoft-MIEngine-Out-l2bxdmon.wx2 --stderr=Microsoft-MIEngine-Error-atwk15nx.rdg --pid=Microsoft-MIEngine-Pid-44bj1vl5.xfn --dbgExe=G:/msys64/opt/t/gdb.exe --interpreter=mi "

Actually, it is because the PATH environment variable set does not take effect, resulting in the inability to find the dependent dynamic library when starting gdb.

gcampbell-msft commented 1 year ago

@WittonBell Thanks for notifying us of this! I think that this is related to #1829 . Marking as a request.

Thanks!