Installing mpc


Before we work on writing this grammar we first need to include the mpc headers, and then link to the mpc library, just as we did for editline on Linux and Mac. Starting with your code from chapter 4, you can rename the file to parsing.c and download mpc.h and mpc.c from the mpc repo. Put these in the same directory as your source file.

To include mpc put #include "mpc.h" at the top of the file. To link to mpc put mpc.c directly into the compile command. On Linux you will also have to link to the maths library by adding the flag -lm.

On Linux and Mac

  1. cc -std=c99 -Wall parsing.c mpc.c -ledit -lm -o parsing

On Windows

  1. cc -std=c99 -Wall parsing.c mpc.c -o parsing

Hold on, don’t you mean #include <mpc.h>?

There are actually two ways to include files in C. One is using angular brackets <> as we’ve seen so far, and the other is with quotation marks "".

The only difference between the two is that using angular brackets searches the system locations for headers first, while quotation marks searches the current directory first. Because of this system headers such as <stdio.h> are typically put in angular brackets, while local headers such as "mpc.h" are typically put in quotation marks.