How to compile and run C in sublime text 3?

前端 未结 12 1203
生来不讨喜
生来不讨喜 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条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 21:17

    Instruction is base on the "icemelon" post. Link to the post:

    how-do-i-compile-and-run-a-c-program-in-sublime-text-2

    Use the link below to find out how to setup enviroment variable on your OS:

    c_environment_setup

    The instruction below was tested on the Windows 8.1 system and Sublime Text 3 - build 3065.

    1) Install MinGW. 2) Add path to the "MinGW\bin" in the "PATH environment variable".

    "System Properties -> Advanced -> Environment" variables and there update "PATH' variable.

    3) Then check your PATH environment variable by the command below in the "Command Prompt":

    echo %path%
    

    4) Add new Build System to the Sublime Text.

    My version of the code below ("C.sublime-build").

    link to the code:

    C.sublime-build

    // Put this file here:
    // "C:\Users\[User Name]\AppData\Roaming\Sublime Text 3\Packages\User"
    // Use "Ctrl+B" to Build and "Crtl+Shift+B" to Run the project.
    // OR use "Tools -> Build System -> New Build System..." and put the code there.
    
    {
        "cmd" : ["gcc", "$file_name", "-o", "${file_base_name}.exe"],
    
        // Doesn't work, sublime text 3, Windows 8.1    
        // "cmd" : ["gcc $file_name -o ${file_base_name}"],
    
        "selector" : "source.c",
        "shell": true,
        "working_dir" : "$file_path",
    
        // You could add path to your gcc compiler this and don't add path to your "PATH environment variable"
        // "path" : "C:\\MinGW\\bin"
    
        "variants" : [
    
            { "name": "Run",
              "cmd" : ["${file_base_name}.exe"]
            }
        ]
    }
    

提交回复
热议问题