Visual Studio 代码在 linux 上找不到 g++ 编译器

Visual Studio Code cannot finde g++ compiler on linux

有谁知道为什么vs-code找不到c++编译器。我已经使用 vc-code 几个月没有任何问题,但是突然没有任何明确的原因它找不到编译器了!!这里有人能找出是什么原因造成的吗?

tasks.json

    {
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command":"g++ $(pkg-config --cflags --libs opencv gl glew sdl2)",
            "args": ["-g", "${workspaceFolder}/*.cpp", "-lstdc++fs", "-pthread"],
             "group":{
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

c_cpp_properties.json

{
    "configurations": [

        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}",
                "/usr/include/c++/6.3.0",
                "/usr/include/c++/6",
                "/usr/include/x86_64-linux-gnu/c++/6",
                "/usr/include/c++/6/backward",
                "/usr/lib/gcc/x86_64-linux-gnu/6/include",
                "/usr/local/include",
                "/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed",
                "/usr/include/x86_64-linux-gnu",
                "/usr/include",
                "/usr/bin"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "/usr/include/c++/6.3.0",
                    "/usr/include/c++/6",
                    "/usr/include/x86_64-linux-gnu/c++/6",
                    "/usr/include/c++/6/backward",
                    "/usr/lib/gcc/x86_64-linux-gnu/6/include",
                    "/usr/local/include",
                    "/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed",
                    "/usr/include/x86_64-linux-gnu",
                    "/usr/include",
                    "/usr/bin"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 3
}

产出

/bin/bash: g++ $(pkg-config --cflags --libs opencv gl glew sdl2): command not found

NOTE:我在vs-code的集成终端中仍然可以使用g++编译文件,但是无法被tasks.json识别!!!

i don't think that this could relate to this problem, cause i have been using it like this for long time with no problem. and in general during the compilation all of this parts gonna be clipped together.

您更新了您的命令,因此您的陈述不再正确。也就是说,您添加了未在 Visual Studio 代码中处理的命令替换 $(...),并按原样在一次命令中传递给 bash。正确的解决方案如下:

"tasks": [
    {
        "label": "echo",
        "type": "process",
        "command":"/bin/bash",
        "args": [ "-c", "g++", "$(pkg-config --cflags --libs opencv gl glew sdl2)", "-g", "${workspaceFolder}/*.cpp", "-lstdc++fs", "-pthread"],
         "group":{
            "kind": "build",
            "isDefault": true
        }
    }
]

或者短一点

"tasks": [
    {
        "label": "echo",
        "type": "process",
        "command":"/bin/bash",
        "args": [ "-c", "g++ $(pkg-config --cflags --libs opencv gl glew sdl2) -g ${workspaceFolder}/*.cpp -lstdc++fs -pthread"],
         "group":{
            "kind": "build",
            "isDefault": true
        }
    }
]