linux - Visual Studio Code 在 Linux 上找不到 g++ 编译器

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

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

任务.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

注意:我在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 Code 中处理并按原样在一次命令中传递给 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
        }
    }
]

关于linux - Visual Studio Code 在 Linux 上找不到 g++ 编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50052729/

相关文章:

c++ - g++链接器的特性错误

c++ - 如何指定编译前默认包含的文件

visual-studio-code - Visual Studio Code URL 突出显示

visual-studio-code - vscode 中的 TAB 和 ENTER 问题

C++ HTTP GET 使用套接字

linux - Scriptella:Jaybird 的 ResourceException

regex - 考虑到特殊的正则表达式,如何正确使用 sed 替换命令的反向引用

c++ - g++ 抛出 "undefined reference to"静态类成员

linux - 严重 - 文件不存在!使用perl脚本监控apache日志时出错

flutter - 在 VSCode 中调试当前打开的 Flutter 文件