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

 

4 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
  1. Sam Brown

    Thanks for this. I just got my BeagleBone out of the box for the first time, and was getting sick of the official docs. I wanted to get to coding ASAP and finding your Hello World example was the gateway I wanted.

    Reply

Leave a Reply

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