Search code examples
vimvim-pluginvimspector

can't build cpp files using "*.cpp" in vimspector


I have this config for cpp, but when i use vimspector#Launch, error appears, it's connected with this string "shell": "g++ -o ${workspaceRoot}/test -g -std=c++2a ${workspaceRoot}/*.cpp" All config code:

{
  "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"
      }
    }
  }
}

If i write g++ -o ${workspaceRoot}/test -g -std=c++2a ${file} in shell istead of "shell": "g++ -o ${workspaceRoot}/test -g -std=c++2a ${workspaceRoot}/*.cpp" it works fine, but i need compile multiple files automatically.


Solution

  • The problem was that in this context the "*" symbol is not correctly interpreted by the command line, so the command "sh" needs to be used.

    "shell": ["sh", "-c", "g++ -o \"${fileDirname}/test\" -g -std=c++2a \"${fileDirname}\"/*.cpp"]
    

    Escaping is necessary for paths with spaces to work.