Saturday, April 6, 2013

Hello World with MacBook Air in C++

I like having a bare-bones setup to write code.  All I need is a dream and:
  • a text editor ( vi, vim, gvim ) 
  • a compiler ( g++ )
  • a terminal
Given that Mac OS X is backed by Unix, I thought it would be simple to get up and running.  As always, it took me longer than expected.  Here's what I did.

Instead of gvim, I installed macvim.  As suggested I moved the MacVim icon to the applications folder.  I also made a copy of the mvim script to /usr/local/bin folder.
  sudo cp ~/Downloads/MacVim-snapshot-66/mvim /usr/local/bin

Now I can open macvim from any terminal directory with commands like:
  mvim
  mvim main.cpp

In order to get the compiler working I installed xcode.  You can write, compile and run code all from xcode, but the compiler isn't available on the command line.  To install the command line tools:
  open xcode -->
    open the xcode menu -->
      open preferences -->
        open the downloads and install the command line tools.

After it all installs, you should be able write a simple c++ file and compile it in the terminal with commands like:
  g++ main.cpp
  ./a.out

No comments:

Post a Comment