C Program in xycode

Posted by ExiaHuang on December 19, 2019

Agenda

Use xycode and Gcc to develope c program.

config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{
    "tasks": [
        {
            "label": "make:version",
            "command": "make -v"
        },
        {
            "label": "make:clean",
            "command": "make clean"
        },
        {
            "label": "make:hello",
            "command": "make hello"
        },
        {
            "label": "make:all",
            "command": "make all"
        },
        {
            "label": "make:target",
            "command": "make ${input:make_target}"
        },
        {
            "label": "gcc:compile",
            "cwd": "${fileDirname}",
            "command": "gcc -o ${fileBasenameNoExtension} ${file}"
        },
        {
            "label": "gcc:compile_and_run",
            "cwd": "${fileDirname}",
            "command": "gcc -o ${fileBasenameNoExtension} ${file} && ${fileBasenameNoExtension}"
        }
    ],
    "variables": {},
    "onSaveEvents": [
        {
            "label": "compile and run c file",
            "description": "compile and run c file after save",
            "filetypes": [".c"],
            "inActive": false,
            "cwd": "${fileDirname}",
            "command": "gcc -o ${fileBasenameNoExtension} ${file} && ${fileBasenameNoExtension}"
        }
    ]
}

write hello world

1
2
3
4
5
6
7
#include <stdio.h>

int main(int argc, char *args[])
{
    printf("Hello, world!\n");
    return 0;
}

After save the file, you can see the result.