0

hello i am a beginner and currently following learncpp 2.8 on how to use multiple code files which i was able to build and run manually but build and fail to run in vs code despite setting tasks.json correctly and having both in the same folder, i am on linux mint gcc11
lerning.cpp (main)

#include<iostream>



int getinteger();
int main()
{
    int x{ getinteger() };
    int y{ getinteger() };

    std::cout << x << " + " << y << " is " << x + y << '\n';
    return 0;
}

getinteger.cpp

#include <iostream>

int getinteger()
{
    std::cout << "Enter an integer: ";
    int x{};
    std::cin >> x;
    return x;
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "Build lerning and getinteger",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "-ggdb",
                "-pedantic-errors",
                "-Wall",
                "-Weffc++",
                "-Wextra",
                "-Wconversion",
                "-Wsign-conversion",
                "-Werror",
                "lerning.cpp",
                "getinteger.cpp",
                "-o",
                "${workspaceFolder}/lerning"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Generated task to build lerning and getinteger"
        }
    ]
}
)

Code-runner: Executor Map

{
    "files.autoSave": "afterDelay",
    "code-runner.runInTerminal": true,
    "extensions.ignoreRecommendations": true,
    "files.insertFinalNewline": true,
    "code-runner.saveAllFilesBeforeRun": true,
    "code-runner.executorMap": {
        


        "javascript": "node",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "zig": "zig run",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "objective-c": "cd $dir && gcc -framework Cocoa  ${fileDirname}/**.cpp-o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "php": "php",
        "python": "python -u",
        "perl": "perl",
        "perl6": "perl6",
        "ruby": "ruby",
        "go": "go run",
        "lua": "lua",
        "groovy": "groovy",
        "powershell": "powershell -ExecutionPolicy ByPass -File",
        "bat": "cmd /c",
        "shellscript": "bash",
        "fsharp": "fsi",
        "csharp": "scriptcs",
        "vbscript": "cscript //Nologo",
        "typescript": "ts-node",
        "coffeescript": "coffee",
        "scala": "scala",
        "swift": "swift",
        "julia": "julia",
        "crystal": "crystal",
        "ocaml": "ocaml",
        "r": "Rscript",
        "applescript": "osascript",
        "clojure": "lein exec",
        "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
        "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
        "racket": "racket",
        "scheme": "csi -script",
        "ahk": "autohotkey",
        "autoit": "autoit3",
        "dart": "dart",
        "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
        "haskell": "runghc",
        "nim": "nim compile --verbosity:0 --hints:off --run",
        "lisp": "sbcl --script",
        "kit": "kitc --run",
        "v": "v run",
        "sass": "sass --style expanded",
        "scss": "scss --style expanded",
        "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
        "FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "sml": "cd $dir && sml $fileName",
        "mojo": "mojo run",
        "erlang": "escript",
        "spwn": "spwn build",
        "pkl": "cd $dir && pkl eval -f yaml $fileName -o $fileNameWithoutExt.yaml",
        "gleam": "gleam run -m $fileNameWithoutExt"
    }
}

tried configuring to run all cpp files but failed

build log "Executing task: Build lerning and getinteger

Build lerning and gebinteger+x

Starting build...

/usr/bin/g++ -fdiagnostics-color-always-g-ggdb -pedantic-errors -Wall -Weffc++ -wextra -Wconversion-wsign-conversion -Werror lerning.cpp getinteger.cpp-o /home/mascarad/Desktop/my projects/c++ project/lerning/lerning!

Build finished successfully.

Terminal will be reused by tasks, press any key to close it."

[error](https://i.sstatic.net/lQbQldQ9.png

i tried using "${fileDirname}/**.cpp" and"${fileDirname}\*.cpp" and just "lerning.cpp","get integer.cpp" and multiple other solutions on posts like this but a lot of them stray of the point like telling me compile manually

25
  • 2
    How do you run the task? Can you show the logs from it running? My crystal ball says you're not using the task, and instead using the infamous "code runner" extension. Commented Jul 8 at 10:29
  • 1
    Please edit your question to copy-paste (as text) the full and complete build output, including the commands used to build. Commented Jul 8 at 10:34
  • 3
    Remove the code-runner plugin. It's bad and clashes with the MS plugin. Commented Jul 8 at 10:53
  • 1
    Why do you want to use code runner? It works without it. I would even recommend a different editor/IDE. VSCode is not beginner-friendly.
    – jabaa
    Commented Jul 8 at 11:42
  • 1
    "it quite similar but none of the answers on that post worked for me" That's not true. The accepted answer works. You insist on using code runner. That's your problem. You are able to build the project without code runner.
    – jabaa
    Commented Jul 8 at 13:47

0