我有这个cpp配置,但是当我使用vimspector#Launch时,出现错误,它与这个字符串连接
"shell": "g++ -o ${workspaceRoot}/test -g -std=c++2a ${workspaceRoot}/*.cpp"
所有配置代码:
{
"adapters": {
"custom-codelldb": {
"extends": "CodeLLDB",
"command": [
"$HOME/Development/vimspector/CodeLLDB/build/adapter/codelldb",
"--port", "${unusedLocalPort}"
]
},
"CodeLLDB - StopOnEntry": {
"extends": "custom-codelldb",
"name": "CoHostingLLDB"
},
"custom-cpptools": {
"extends": "vscode-cpptools",
"command": [
"$HOME/Development/vimspector/MIEngine/bin/Debug/vscode/OpenDebugAD7"
]
}
},
"configurations": {
"CodeLLDB": {
"adapter": "CodeLLDB",
"variables": {
"BUILDME": {
"shell": "g++ -o ${workspaceRoot}/test -g -std=c++2a ${workspaceRoot}/*.cpp"
}
},
"configuration": {
"request": "launch",
"expressions": "native",
"program": "${workspaceRoot}/test"
}
}
}
}
如果我在 shell 中写
g++ -o ${workspaceRoot}/test -g -std=c++2a ${file}
而不是 "shell": "g++ -o ${workspaceRoot}/test -g -std=c++2a ${workspaceRoot}/*.cpp"
它工作正常,但我需要自动编译多个文件。
问题是在这种情况下,命令行无法正确解释“*”符号,因此需要使用命令“sh”。
"shell": ["sh", "-c", "g++ -o \"${fileDirname}/test\" -g -std=c++2a \"${fileDirname}\"/*.cpp"]
对于带有空格的路径来说,转义是必要的。