dissabte, de maig 05, 2012

How to install flex in a Mac

I've been googling how to install flex (the lexical analyzer) on a Mac. The solutions proposed seemed illogical and difficult. In one of the pages, someone said that it was included in Xcode. This pointed me in the right direction.
If you have Xcode installed and you open a terminal and type flex, it says "command not found". I have two Xcode's installed, version 3.2.5 which I installed the usual way, and version 4.3.2, which I installed through the AppStore, it did not uninstall the previous version.
So the steps are:

  1. Open Xcode (I opened the newer version, 4.3.2)
  2. Choose in the Xcode menu, Open Developer Tool, and then More Developer Tools
  3. This will take you to the Apple Developer web and will allow you to download the "Command line tools for Xcode"
  4. I chose the latest version available, Late March 2012
  5. When the 170-MB dmg file finished downloading I installed it.
  6. I reopened the terminal
  7. Typing "flex --version" now gives "flex 2.5.35".
  8. This also installs other command-line goodies like Apple compilers (which are included in Xcode but not executable in the command line) and things such as bison, the companion to flex.