At the begining

[Part of the passage was set to hidden.]

Why this article

Just for record. In junior & senior high school, we prefer to use Dev-C++ when it comes to Windows OS, and vim/emacs when macOS/Linux just for simulating the competetion situation perfectly. As I am in a college learning programming language now, I suggest a UI-based development environment.
Besides, lots of friends started learning C/C++ language and they have no idea what to do with macOS. I wish this is helpfulヾ(・ε・`*)

Let's start

Select an editor

It's commonly recommended by Professors and Teachers to use Xcode on macOS. However we really DON'T need such a comprehension-chanllenging, powerful, professional, complex space-taker like that.
Below are standards what we want for current learning level:

  1. Easy to use
  2. Free
  3. Capable for most environment / Cross-platform
  4. Works well / Update frequently / Community-based
  5. Compile and Run code in a simple way [This is extremely significant beacause it'll drive you crazy if not]

Following are editors I have already tried and found unable to deal with the issue currently:

  • Visual Studio Code
  • Sublime Text 3

Finally I chose Atom as the editor.

A hackable text editor for the 21st Century

Official website: https://atom.io

Prepare software and Compiler(s)

If anything inapproprite or doesn't work, feel free to leave a word on the bottom of this page:)

Editor - Atom

  • Download Atom via its official site: https://atom.io
  • Unzip and drag into Application folder

Compiler - gcc

It's okay and supported by Apple absolutely to install Xcode, which is containing EVERYTHING you are going to use. But that's unacceptable since the SSDs are getting more expensive these days.

  • Open Terminal App, enter the command
    xcode-select --install

The command will install Xcode Command Line Tools to your Mac, which is what we needed.
This is the SAME when you input gcc before Xcode Command Line Tools were installed.

  • Check the command "gcc", and its return should be like this
    Screen Shot 2018-10-28 at 00.39.24.png

Set up Atom

Install plugins

  1. Press "⌘"+"," to open Atom prefrences.
  2. Go "Install", search "gpp-compiler", and click "Install". When installation is done, it shoule be like this:
    Screen Shot 2018-10-28 at 00.58.46.png
  3. Go "gpp-compiler"

    • Untick "Compile to Temporary Directory"
      This is for your getting a clearer output excutable file in current directiory where you saved your code.WechatIMG3 1.jpeg
    • Untick "Keybindings"
      This is because fingers are going to be tired since the distance between "fn" and "F5" on keyboard is awkward to some extent.WX20181028-010315@2x.png
    • Go "Atom"->"Keymaps", add following text to the end of file: 'atom-text-editor': 'ctrl-x': 'gpp-compiler:compile'
      This is for binding Hot Key "control"+"x" to compile and run the code. The gap between "control" and "X" is far more small than the previous one, still you can change it to any you want.

Enjoy the high efficient developing environment :-D

Demo:


Issues

Update on Oct 29th, 2018

Issue #1

I found things doesn't work normally today just like the video:

As we can see, Atom compiled [2018.10.29.c] successfully to an out put file [2018.10.29], however it hasn't poped up the Terminal window and run the excutable file [2018.10.29].

Reason

The filename are supposed to contain two or more DOTS ".", for the plugin gpp-compiler is going to identify the file inproperly.

Solution

There are two ways to this problem.
Way 1. Make sure to name the file with ONLY ONE DOT (e.g.: "your_file_name.c")
Way 2. PROBLEM TO BE SOLVED, DID NOT FOUND AN APPLIABLE SOLUTION THIS WAY YET.
Go "Settings"->"Packages"->"gpp-compiler"->"View Code".

  • Now we have a check on the source code of this plugin.
  • Since there are only ONE file (.js) for main program, we need only to check on this file ("index.js")

    • In line #309, found "if (atom.config.get("gpp-compiler.runAfterCompile"))", follow up;
    • In line #407, found "process.platform === "darwin"". macOS are going to open terminal with the command open, follow up;
    • In line #411 - #413, found the code:
child_process.spawn("open", [
        getCompiledPath(info.dir, info.name)
], options);
- It seems normal as we see. Let's make the value of the return of the function `getCompiledPath()` and write in to the log file.

fs.writeFile(path.join(info.dir, "log_run_code.txt"), getCompiledPath(info.dir, info.name));

- Quit Atom and restart to make sure the plugin is reloaded successfully and our changes are applied.
We found it'll run the command `open /Users/victor/Desktop/BDIC/Workspace/C/2018.10.29`, and macOS returned error when excuted:![Screen Shot 2018-10-29 at 16.35.20.png](//g1.urox.cn/usr/uploads/2018/10/1928776052.png)
Last modification:October 29th, 2018 at 04:49 pm