Question: I am working on a Raspberry Pi project whereby we need to program a robot to run by itself.

Currently I am using Geany as the Environment and C programming language. The steps are obtained from the following tutorial:

<http://www.raspberry-projects.com/pi/programming-in-c/getting-your-raspberry-pi-ready-for-c-programming>

However because I have never done this before, I encountered a problem. The website says Geany requires a 'makefile' to execute the program. I created a simple main.c and makefile

### main.c

```
int main(int argc, char **argv)
{
    printf("Hello world!");
    return 0;
}

```

### makefile

```
CC=gcc                  
CFLAGS=-I.
DEPS =                  

all: main.o 
    gcc main.o -o target_bin

main.o: main.c 
    gcc -I . -c main.c

clean:
    rm -rf *.o
    rm target_bin

```

From Geany, I tried to Build/Compile/Make but I keep getting error like:

> 
> 'make' is not recognized as an internal or external command
> 
> 
> 

I tried compiling the `main.c` via command prompt, but it still prompts me with the same error:

> 
> 'gcc' is not recognized as an internal or external command,
> 
> 
> 

In summary, I have no idea how to make a makefile. Can anyone guide me?

Answer: 
Execute `sudo apt-get install build-essential` to install the compiler and a bunch of other goodies. I would execute `sudo apt-get update` first to ensure your system is up to date.

For the GNU `make` docs:

<http://www.gnu.org/software/make/manual/make.html>
It's better to write make file like this:

```
CC  = $(CROSS_COMPILE)gcc
LD  = $(CROSS_COMPILE)ld
LDFLAGS = 
CFLAGS  = -g -Wall

TARGETS = main
#     

main:main.o
    $(LD) $(LDFLAGS) -o $@ $<

main.o:main.c
    $(CC) $(CFLAGS) -o $@ $<

clean:
    rm -rf $(TARGETS)
    rm -rf *.o

```

When you work with cross toolchains, you can just do this:

```
make CROSS_COMPILE=your toolchains's prifix

```

then you can get the binary you want.