Visual Studio Code无法在linux上找到g ++编译器

时间:2018-04-26 22:29:04

标签: linux visual-studio-code g++ vscode-settings vscode-tasks

有谁知道为什么vs-code无法找到c ++编译器。我已经使用了几个月的vc代码没有任何问题,但突然没有任何明确的理由它再也找不到编译器!这里有人可以找出导致这种情况的原因。

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

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

1 个答案:

答案 0 :(得分:0)

  

我不认为这可能与这个问题有关,因为我已经很长时间没有问题地使用它了。一般来说,在编辑过程中,所有这些部分都会被夹在一起。

您更新了命令,因此您的陈述不再是真实的。即,您添加了未在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
        }
    }
]