Thread: How to configure VS Code for building and compiling C++ by Control-Shift-B?

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    1

    How to configure VS Code for building and compiling C++ by Control-Shift-B?

    In C++ in VSCode I wrote a program and when I wanted to configure it I created and configured a tasks.json and c_cpp_properties.json and then command-shift-b d it and that built it (created the binary file) and then in the integrated terminal I had to ./(thebinaryfile) for it to run. What code do I have to put in tasks.json OR c_cpp_properties in order for it to not only build, but also run, when I hit Control-shift+b? From which JSON file do I alter the command for execution and what code should I add/replace? I have read all the MS provided docs and Googled but still find myself confused.


    My c_cpp_properties.json file is c_cpp_properties.json - Pastebin.com.


    Code:
    {
        "configurations": [
            {
                "name": "Mac",
                "includePath": [
                    "/usr/local/include", "/Users/me/Downloads/SFML-2.5.1-macos-clang/include"
                ],
                "defines": [],
                "macFrameworkPath": [
                    "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
                ],
                "compilerPath": "/usr/bin/clang++",
                "cStandard": "c11",
                "cppStandard": "c++17",
                "intelliSenseMode": "clang-x64"
            }
        ],
        "version": 4
    }
    My tasks.json file is { "version": "2.0.0", "tasks": [ { "label": "ech - Pastebin.com


    Code:
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "echo",
                "type": "shell",
                "command": "echo Hello"
            },
            {
                "type": "shell",
                "label": "clang++ build active file",
                "command": "/usr/bin/clang++",
                "args": [
                    "-g",
                    "${file}",
                    "-o",
                    "${fileDirname}/${fileBasenameNoExtension}",
                    "-I/Users/me/Downloads/SFML-2.5.1-macos-clang/include",
                    "-L/Users/me/Downloads/SFML-2.5.1-macos-clang/lib",
                    "-lsfml-graphics",
                    "-lsfml-window",
                    "-lsfml-system",
                    "-lsfml-audio"
                ],
                "options": {
                    "cwd": "/usr/bin"
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": "build"
            },
            {
                "type": "shell",
                "label": "clang build active file",
                "command": "/usr/bin/clang++",
                "args": [
                    "-g",
                    "${file}",
                    "-o",
                    "${fileDirname}/${fileBasenameNoExtension}"
                ],
                "options": {
                    "cwd": "/usr/bin"
                }
            }
        ]
    }
    My code is #include <SFML/Graphics.hpp> int main() { sf::RenderWindow window(sf::V - Pastebin.com .


    Code:
    #include <SFML/Graphics.hpp>
     
    int main()
    {
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);
     
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                    window.close();
            }
     
            window.clear();
            window.draw(shape);
            window.display();
        }
     
        return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 05-19-2013, 04:16 PM
  2. logical shift and arithmetic shift.(bit shifting in C )
    By A34Chris in forum C Programming
    Replies: 20
    Last Post: 09-03-2012, 11:22 AM
  3. compiling a program that has no configure script
    By serfurj in forum Linux Programming
    Replies: 9
    Last Post: 02-09-2005, 10:53 AM
  4. Building a tab custom control
    By Mithoric in forum Windows Programming
    Replies: 19
    Last Post: 03-06-2004, 09:34 AM
  5. Shift key extended code
    By Unregistered in forum Game Programming
    Replies: 5
    Last Post: 08-23-2002, 12:35 PM

Tags for this Thread