0

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 !!!

Bobo Feugo
  • 162
  • 1
  • 10
  • It looks like you have an extra space after "g++ " in the "command"... I'm guessing VS Code doesn't strip whitespace there. – Zrax Apr 26 '18 at 22:41
  • Actually it worked very well for that particular example after i deleted the extra space, but now i got the same problem when i give more option to the compiler. I have edited the post – Bobo Feugo Apr 26 '18 at 23:01
  • 1
    ... Why would you put the arguments in`command` instead of `args`? – Ignacio Vazquez-Abrams Apr 26 '18 at 23:08
  • 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. – Bobo Feugo Apr 26 '18 at 23:19
  • You might also want to configure and/or enable g++. Then include its path too "/usr/lib/g++/x86_64-linux-gnu/6/include", ..... – Juniar Apr 27 '18 at 14:45

1 Answers1

0

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
        }
    }
]
273K
  • 29,503
  • 10
  • 41
  • 64
  • actually the settings you shown above worked well as before, so thanks for pointing that out!, but i still can't figure out why the settings i shown in my question, suddenly become not more applicable! Cause i have been using it this way for more than a year with no problem, but suddenly after an update the task was not able to recognize the g++ compiler!!! – Bobo Feugo May 15 '18 at 16:31