Search code examples
ccontiki

How to run hello-world in Contiki OS?


I am new to contiki os, I tried to compile and run hello-world.c file located in examples directory in contiki os 3.0. But I got the error,

hello-world.c:40:21: fatal error: contiki.h: No such file or directory".

I tried this in root user.

enter image description here

Any kind of help to run very beginner program in contiki is appreciated.


Solution

  • Use the make command to build Contiki. Doing that invokes architecture-specific version of gcc with compiler flags pointing to the the proper header file paths:

    By default, make is going to build for the "native" platform (that is, x86) and create an application image that is executable on the host PC.

    To build for a specific hardware platform, set the TARGET variable. For example, to build for Tmote Sky/TelosB nodes:

    make TARGET=sky hello-world
    

    To build and run for the native platform:

    make
    

    Output:

    TARGET not defined, using target 'native'
    mkdir obj_native
    ...
    CC        hello-world.c
    LD        hello-world.native
    rm hello-world.co
    

    To run it:

    ./hello-world.native 
    

    Output:

     Contiki-3.x-1457-g552408b started with IPV6, RPL
     Rime started with address 1.2.3.4.5.6.7.8
     MAC nullmac RDC nullrdc NETWORK sicslowpan
     Tentative link-local IPv6 address fe80:0000:0000:0000:0302:0304:0506:0708
     Hello, world