Make on a Raspberry Pi "not recognized as an internal or external command"

7.2k views Asked by At

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?

3

There are 3 answers

1
Ken On

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

2
liunx On

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.

0
Miphix On

All the above commands are in typed into what linux users know as terminal(for you windows guys, it's technically command prompt. What you need to learn in order to understand the suggestions given is how to create a telnet connection with your RPi device. As well as how to distinguish commands that are internet dependant such as apt-get. Sudo is a temporary root permission for the line of command to be typed out after sudo. I suggest exploring either ubuntus wiki or archs wiki. Get used to google and C.L.I.