1

In Visual studio code, I can compile and debug one C++ file easily. But when it comes to multiple C++ file with some header file, it does not work.

Here is the default tasks.json file

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

What changes do I have to make?

Xited
  • 69
  • 7
  • 2
    I think the issue may be that the second argument passed to `g++` is `${file}`. This may indicate VSCode passes the current file as an argument to `g++` and not all the files. What about a build system like CMake/Bazel/etc? – Raz Rotenberg Mar 11 '20 at 08:28
  • 1
    Does this answer your question? [VS Code will not build c++ programs with multiple .ccp source files](https://stackoverflow.com/questions/47665886/vs-code-will-not-build-c-programs-with-multiple-ccp-source-files) – Lukas-T Mar 11 '20 at 08:32
  • In the linked duplicate the first and second answer seem both valid. But @RazHaleva is right, sooner or later you will want to use a proper build system. – Lukas-T Mar 11 '20 at 08:34
  • I tried with replacing ```${file}``` with ```${fileDirname}/*.cpp``` but it did not worked. And I don't know what is ```CMake/Bazel/etc```. – Xited Mar 11 '20 at 08:39
  • I guess I have to learn cmake. – Xited Mar 11 '20 at 08:47
  • What didn't work? But learning cmake is quite useful in my opinion anyway. – Lukas-T Mar 11 '20 at 09:04

0 Answers0