How to compile and run C in sublime text 3?

前端 未结 12 1173
生来不讨喜
生来不讨喜 2020-11-30 20:33

I would like to compile and run C program in sublime text 3 on ubuntu 14.04. Currently the program is being compiled with gcc using sublime text 3 executing a command (see b

12条回答
  •  Happy的楠姐
    2020-11-30 21:20

    After a rigorous code-hunting session over the internet, I finally came up with a solution which lets you compile + run your C code "together at once", in C99, in a dedicated terminal window. I know, a few people dont like C99. I dont like a few people either.

    In most of the cases Sublime compiles and runs the code, but in C90 or a lesser version. So if you specifically want it to be C99, this is the way to go.

    NOTE: Btw, I did this on a Windows machine, cannot guarantee for others! It probably won't work there.

    1. Create a new build system in Sublime: Tools > Build System > New Build System...

    2. A new file called untitled.sublime-build would be created.

    Most probably, Sublime will open it for you.

    If not, go to Preferences > Browse Packages > User

    If the file untitled.sublime-build is there, then open it, if it isn't there, then create it manually and open it.

    3. Copy and paste the given below code in the above mentioned untitled.sublime-build file and save it.

    {
        "windows":
        {
            "cmd": ["gcc","-std=c99" ,"$file_name","-o", "${file_base_name}.exe", "-lm", "-Wall", "&","start", "${file_base_name}.exe"]
        },
        "selector" : "source.c",
        "shell": true,
        "working_dir" : "$file_path",
    }
    

    Close the file. You are almost done!

    4. Finally rename your file from untitled.sublime-build to myC.sublime-build, or you might as well show your creativity here. Just keep the file extension same.

    5. Finally set the current Build System to the filename which you wrote in the previous step. In this case, it is myC

    Voila ! Compile + Run your C code using C99 by Tools > Build , or by simply pressing Ctrl + B

提交回复
热议问题