Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding my own library to Contiki OS

I want to add some third party libraries to Contiki, but at the moment I can't. So I wanted to just test with a simple library.

I wrote two files hello.c hello.h, in hello.c I have:

printf(" Hello everbody, library call\n");

In hello.h I have:

extern void print_hello();

I created hello.o using the command:

msp430-gcc -mmcu=msp430f1611 hello.c -o hello.o

I created an archive file:

ar -cvq libhello.a hello.o

I move to contiki, i write a simple program that calls hello.h to execute a function.I try to include hello.a using PROJECT LIBRARIES variable in the makefile, when i compile i get this :

  Hello_lib.sky section .vectors' will not fit in region'vectors'
  ...
  region vectors overflowed by 32 Bytes

Can someone please explain me what is the problem (I am new to the field) ?

And how to correct it if possible? ( What options should i specify for msp430-gcc) Thanks.

like image 959
yushaa yave Avatar asked Oct 20 '22 12:10

yushaa yave


2 Answers

Make sure you build the library for the same architecture you build your program.

For example, if you want to use build an executable for sky motes (MSP430F1611 MCU), build the library with:

msp430-gcc -mmcu=msp430f1611 -c hello.c -o hello.o
msp430-ar -cvq libhello.a hello.o

Then add the path to the library and its name to application's Makefile:

TARGET_LIBFILES += -L./hellolib -lhello

Then build the application as usual:

make TARGET=sky
like image 122
kfx Avatar answered Oct 29 '22 18:10

kfx


This video shows how to add your own libraries to Contiki OS

https://www.youtube.com/watch?v=csa9D1U5R_8

Details:

  • The library that i create is: libhello.a
  • The library just prints the message "Hello everbody, library call"
  • I included the library to the Contiki example "example-broadcast.c"

Steps of the video:

  1. Create folder example:

    • Copy the example-broadcast.c

    • Copy the Makefile

  2. Create the library:

    • Create object file:

      msp430-gcc -mmcu=msp430f1611 -c hello.c -o hello.o
      
    • Create library file:

      msp430-ar -cvq libhello.a hello.o
      
  3. Tell Contiki the path to the library:

        TARGET_LIBFILES += -L. -lhello
    
  4. Add the library to your .c code and print the hello message:

     #include "hello.h"
     Print_Function();
    
  5. Compile your .c code:

     make example-broadcast TARGET=sky
    
like image 37
Sgio Dz Avatar answered Oct 29 '22 18:10

Sgio Dz