microsoft / microsoft/vscode-cmake-tools
environment PATH in `settings.json` `launch.json` not effect
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 546
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 32
Description
# 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:
```cpp
#include
using namespace std;
int main(int argc, char* argv[])
{
cout << "Hello, CMake" << endl;
return 0;
}
```
CMakePresets.json:
```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
```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
```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
}
]
}
]
}
```
5. 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
```
6. 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.
Contributor guide
Research direction
Reproduce the failure using CMakePresets.json, .vscode/settings.json, and .vscode/launch.json, starting with the CMake debug button and the `(gdb) start` entry point. Compare the reported PATH handling with the gdb startup output; done means the configured PATH is available when launching gdb and debugging starts successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, vscode
- Domain
- build-system, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100