Installing a C Compiler and IDE

From Mech
Jump to navigationJump to search

Introduction

One of the purposes of this course is to learn the basics of the C programming language. Towards that goal, we will begin the course by writing some simple C programs that are built to run on a computer alone, and not any sort of microprocessor. This section will guide you through setting up a C-language compiler and an integrated development environment or IDE.

Note that if you already have a compiler and/ or IDE that you are comfortable and experienced with this page may be of little use to you.

Setting up a compiler

Unlike some languages that you may be familiar with (MATLAB for one) the C programming language must be "compiled" before it can be run on the computer. A compiler's job is to take the code that a person writes in the C-language and convert it to a "binary file" in machine language that the computer understands. For more info see wikipedia.

The compiler that we recommend is the GNU Compiler collection or GCC. This is a widely used cross-platform compiler toolsuite that has libraries and compilers for C, C++, Fortran, Java, and more. Additionally the compiler that we will use later on in the course for compiling C code to run on the PIC32 is based on GCC.

In the next section we are going to discuss setting up an integrated development environment (IDE) called NetBeans. They have very thorough directions for setting up the GCC compiler on every operating system here.

Windows

Windows is arguably the most difficult operating system to get the compiler working with. The GCC toolsuite was originally developed to work with Unix/Linux operating systems, but there are two popular Windows ports available, Cygwin and MinGW.

MinGW is probably the easier of the two to setup so that is what we recommend. Complete, detailed instructions for this process can be found here.

A quick summary of these steps is provided in the following:

  1. Install MinGW-5.1.4.exe (direct link).
  2. Add C:\MinGW\bin to the system path by editing your system's Environment Settings.
  3. Install MSYS 1.0 files by running MSYS-1.0.10.exe (direct link).
  4. Install the gdb debugger by downloading gdb-6.8-mingw-3.tar.bz2 (direct link) and extracting using WinZip, gzip, or 7-zip such that the gdb executable is in the C:\MinGW\bin directory.


Apple OSx

To get all of the required tools you must install Xcode and X11 from the Apple Developer Connection. Note that you must sign up for a free ADC membership.

Linux

Many linux distributions have GCC bundled with the install, if you do not have it you should be able to get it from your distribution's repositories using your favorite package manager.

Setting up the IDE

Now that you have a compiler, all you really need is a text editor, and you are ready to start coding in C. However, learning the ins and the outs of compiling, linking, debugging, Makefiles, etc. can be a bit overwhelming. So we are going to recommend the use of an IDE to help you get started. As well as helping beginners, many experienced programmers do all of their development in an IDE. An IDE can act as a source code editor, it can provide graphical interfaces to debuggers and compilers, it can autogenerate useful configuration files, and many more useful features. The IDE that we are going to recommend is NetBeans. NetBeans is totally free, it is cross-platform, and Microchip has paired with NetBeans to develop their new-generation IDE for PIC development, MPLABX (which you will be using later in the course).

To install NetBeans simply visit this link and install either 6.9.1 or 7.0.1 for your operating system. You can install either the full version, or just the C/C++ version (recommended). Note that this doesn't really matter as modules can be added or deleted later on. More detailed tips on configuring and troubleshooting can be found here.

Additionally a decent tutorial on setting up and configuring C/C++ projects within NetBeans can be found here.

Test Programs

Conclusions