Adding my own library to Contiki OS

馋奶兔 提交于 2020-01-02 04:07:09

问题


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.


回答1:


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



回答2:


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
    


来源:https://stackoverflow.com/questions/29971717/adding-my-own-library-to-contiki-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!