[英]C++: Why can't I open a file with a relative path?
以前用Visual Studio 2019開發C和C++程序,現在轉到VS Code,調試的時候發現不能用相對路徑打開文件,只能用絕對路徑才能工作。
這是我的 launch.json 和 tasks.json 文件:
發射.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\mingw64\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
任務.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
非常感謝你解決了我的問題。
從應用程序的當前工作目錄遇到相對路徑,並且您已提供
"cwd": "C:\\mingw64\\bin",
如果您想從當前項目根目錄運行,請將其設置為這樣(或將其設置為您喜歡的位置)
"cwd": "${workspaceRoot}"
編輯:如果您以這種方式設置它以便能夠運行gcc
考慮在您的 PATH 變量中添加C:\\mingw64\\bin
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.