Home > Development Tools > VSCode > How to create a C language project with vscode

How to create a C language project with vscode

王林
Release: 2020-02-11 11:32:49
Original
22852 people have browsed it

How to create a C language project with vscode

1. Download the plug-in C/C, C Intellisense;

2. Create a new empty folder and open it from VSCode. (or File-->Open Folder-->Create an empty folder);

3. Press F5 (use the command line gcc, g; or write a makefile, make;), select C ( GDB/LLDB), generate launch.json (for debugging);

4. Modify launch.json, change

"program": "enter program name, for example ${workspaceFolder}/a.out"
Copy after login

to

"program": "${workspaceFolder}/ProjectName";"externalConsole": true
Copy after login

to indicate that the output will pop up command line. If changed to false, it will be output in the terminal inside VSCode.

5. Ctrl Shift B, select tasks.json-->Template--->other, generate tasks.json (create tasks);

6. Modify tasks .json,

"command": "echo Hello"
Copy after login

is changed to

"command": "g++ -o ProjectName ProjectName.cpp"
Copy after login

The ProjectName here has the same name as the ProjectName in 5

7. For complex projects, "command": "echo Hello" changed to "command": "make"

8. Create the makefile again and edit it;

9. Write the Hello.cpp file

10. Press Ctrl Shift P, select Task:Run Tasks, execute task

11. Press F5, execute

The source code is as follows:

Hello.cpp

#include <iostream>
using namespace std;
int main()
{
    cout << "Hello, world!" << endl;
    return 0;
}
Copy after login

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/Hello",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
Copy after login

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "make"
        }
    ]
}
Copy after login

makefile or Makefile

# objects= main.o kbd.o command.o display.o insert.osearch.o files.o utils.o 

# edit: $(objects)

#     cc-o edit $(objects)

# main.o: main.c defs.h

#     cc-c main.c

# kbd.o: kbd.c defs.h command.h

#     cc-c kbd.c

# command.o: command.c defs.h command.h

#     cc-c command.c

# display.o: display.c defs.h buffer.h

#     cc-c display.c

# insert.o: insert.c defs.h buffer.h

#     cc-c insert.c

# search.o: search.c defs.h buffer.h

#     cc-c search.c

# files.o: files.c defs.h buffer.h command.h

#     cc-c files.c

# utils.o: utils.c defs.h

#     cc-c utils.c

# clean:

#     rmedit $(objects)

edit: Hello.o

    cc-o edit $(objects)

Hello.o: Hello.c

    cc-c Hello.c

clean:

    rmedit Hello.o
Copy after login

Recommended related article tutorials: vscode tutorial

The above is the detailed content of How to create a C language project with vscode. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template