How to compile and run a simple C program with Sublime Text 2?

后端 未结 5 1146
青春惊慌失措
青春惊慌失措 2020-12-02 21:58

I want to compile a simple C program with GCC. What do I need to put in the sublime-build file to do so?

5条回答
  •  鱼传尺愫
    2020-12-02 22:03

    For Mac

    {
    "cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && osascript -e 'tell application \"Terminal\" to activate do script \"clear&&${file_path}/${file_base_name} && read -p \\\"Press Enter to exit.\\\"&&exit\"'"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    
    "variants":
    [
        {
            "name": "Run",
            "cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
        }
    ]
    

    }

    For windows

    {
    "cmd": ["g++", "${file}", "-o","${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:?(.*)$",
    "working_dir": "${file_path}",
    "encoding":"cp936",
    "selector": "source.c",
    "variants":
    [
        {
        "name": "Run",
        "cmd": ["cmd","/C","start","cmd","/c", "${file_path}/${file_base_name}.exe &pause"]
        }
    ]
    }
    

    The configuration files above make you input data in the terminal(Mac) or cmd(windows),the output also was shown in the terminal or cmd。

提交回复
热议问题