Adding my own library to Contiki OS
I want to add third party libraries to Contiki, but at the moment I cannot. So I just wanted to test 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'm going to contiki, I'm writing a simple program that calls hello.h to execute a function. I am trying to include hello.a using the 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 to me what the problem is (I'm new to this area)?
And how to fix it if possible? (What parameters should I specify for msp430-gcc) Thanks.
source to share
Make sure you are building a library for the same architecture as your program.
For example, if you want to use build for the 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 library path and name to your Makefile application:
TARGET_LIBFILES += -L./hellolib -lhello
Then create the application as usual:
make TARGET=sky
source to share
This video shows how to add your own libraries to Contiki OS
https://www.youtube.com/watch?v=csa9D1U5R_8
More details:
- The library I'm building is: libhello.a
- The library just prints the message "Hello everbody, library call"
- I have included the library in the Contiki example "example-broadcast.c"
Video steps:
-
Create an example folder:
-
Copy example-broadcast.c
-
Copy Makefile
-
-
Create a library:
-
Create object file:
msp430-gcc -mmcu=msp430f1611 -c hello.c -o hello.o
-
Create library file:
msp430-ar -cvq libhello.a hello.o
-
-
Tell Contiki the path to the library:
TARGET_LIBFILES += -L. -lhello
-
Add the library to your .c code and print a welcome message:
#include "hello.h" Print_Function();
-
Compile the .c code:
make example-broadcast TARGET=sky
source to share