0

I'm relative new and recently started learning OOPS from an online course, The problem I m facing with VSCODE is that I'm not able to create separate files for a single bulky code. I came across some solutions on stack overflow itself and I modified my task.json and launch.json accordingly.

Now the compiler is able find all the related files to the main.cpp, but when I try to run and build my code it says "Error Exists after running preLaunchTask 'C/C++:gcc.exe build active file;.

here is the source code below

main.cpp

 #include <iostream>
 #include "Account.h"

 using namespace std;

int main() {
Account frank_account;
frank_account.set_name("Frank's account");

return 0;
}

account.cpp

#include "Account.h"
void Account::set_name(std::string n) {
    name = n;
}
std::string Account::get_name() {
    return name;
}

account.h

    #ifndef _ACCOUNT_H_
#define _ACCOUNT_H_
#include <string>

class Account
{
private:
    // attributes
    std::string name;
    double balance;

public:

    void set_name(std::string n);
    std::string get_name();

};

#endif

tasks.json

    {
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: g++.exe build active file",
      "command": "C:\\ProgramData\\chocolatey\\bin\\g++.exe",
      "args": [
    "-g",
    "${fileDirname}\\**.cpp",
    "${fileDirname}\\**.h",
    "-o",
    "${fileDirname}\\${fileBasenameNoExtension}.exe"
  ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Task generated by Debugger."
    }
  ],
  "version": "2.0.0"
}

launch.json

  {
"version": "0.2.0",
"configurations": [
  {
    "type": "node",
    "request": "launch",
    "name": "Launch Program",
    "skipFiles": ["<node_internals>/**"],
    "program": "${file}",
    "preLaunchTask": "g++.exe build active file"
  }
]

}

On running main.cpp I get this error "Error Exists after running preLaunchTask 'C/C++:gcc.exe build active file;. I Click on debug anyway so it says main does not exist

my terminal says fatal error: string: No such file or directory 3 | #include

  • Begin by showing us your `tasks.json` file that you use to build. Then copy-paste the full and complete build output into the question as well. – Some programmer dude Jul 27 '23 at 07:15
  • @Someprogrammerdude I have added my tasks.json as well as launch,json here – Shivang Mathur Jul 27 '23 at 07:17
  • There's a problem in your `tasks.json` file, where you only pass `"${file}"` as argument to the compiler. That will build the file in the currently active tab, nothing more. You need to list *all* source files. I also recommend you look into build systems like Make or CMake to help you set up rules for building larger multi-file projects. – Some programmer dude Jul 27 '23 at 07:17
  • @Someprogrammerdude I have added "${fileDirname}\\**.cpp", "${fileDirname}\\**.h", – Shivang Mathur Jul 27 '23 at 07:20

0 Answers0