Search code examples
linuxg++visual-studio-codevscode-tasks

Visual Studio Code cannot finde g++ compiler on linux


Does anyone knows why vs-code can't find c++ compiler. I have used vc-code for several months without any problems, but suddenly without any clear reason it can't find the compiler anymore!! does somebody here can figure out what could be causing this.

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
}

output

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

NOTE: I still can use g++ to compile files in the integrated terminal in vs-code, but it cannot be recognized by tasks.json !!!


Solution

  • 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.

    You updated your command so your statement is not true more. Namely you added command substitution $(...) that is not processed in Visual Studio Code and passed as is in once command to bash. The right solution is below:

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

    Or bit shorter

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