Install BeagleBone C Build Environment and Write Hello World for BeagleBone Using C and a Makefile

All these instructions are to be run on the Beaglebone itself using putty.

Install the C Compiler, make and a few other bits and pieces with

opkg install task-native-sdk

Make a folder for your code by running

mkdir code

cd code

Now create a makefile using nano

nano Makefile

Paste the following code and then press ctrl+O and then ctrl+x

CC = gcc
CFLAGS = -Wall -g -O2
OBJECTS = main.o

all: $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o main

Now create the C source file by running

nano main.c

Paste the following code and then press ctrl+O and then ctrl+x

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main (int argc, char **argv)
{
printf (“Hello from BeagleBone”);
return 0;
}

To compile your new application run

make all

To run your application

./main

 

3 thoughts on “Install BeagleBone C Build Environment and Write Hello World for BeagleBone Using C and a Makefile

    1. Tim Burkert

      You need tabs to indent the lines underneath each target.

      CC = gcc
      CFLAGS = -Wall -g -O2
      OBJECTS = main.o

      all: $(OBJECTS)
      $(CC) $(CFLAGS) $(OBJECTS) -o main

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>