Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to create a reusable library file from c-code.

Status
Not open for further replies.

ravi1488

Member level 3
Joined
Apr 21, 2010
Messages
60
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Location
India
Activity points
1,656
How to create a library file ".a" file from a c-code. I want to make a common library file that i can use in my embedded c code. I want to use that with AVR microcontrollers. Please explain from first step with exampple ...thank you.
 

Please give us more details. How you would like to use this library?
 
Why don't you make a simple h and .c library, the majority of libraries are in C format unless you want to distribute it and you want to hide the code.
 
I would like to use this library in my c code. for example , I make a library function that gives average of two numbers.
So later I use that library function in my code . I want to make library function to hide that piece of my algorithm.
 

I would like to use this library in my c code. for example , I make a library function that gives average of two numbers.
So later I use that library function in my code . I want to make library function to hide that piece of my algorithm.

What you are referring to is commonly known as an Archive or Library Archive file. The procedure to build such a file is not particularly difficult, archives are routinely used on higher order systems like Linux.

The following example demonstrates the use of GCC's archiver (ar) utility to build a simple library archive:

**broken link removed**

If you have a standard GCC Compiler installed on a PC, you might want to practice a bit before cross compiling for the AVR.



The AVR-GCC toolsuite has an archiver adeptly named avr-ar, the following links provide a few examples of its use:

Creating an AVR Archive/Library File

How do I create a static library for the AVR Atmega328p?

There are several "gotchas" which can arise when building an archive, particularly when coding for embedded devices, careful planning can greatly increase the flexibility of an archive file.


BigDog
 
I have tried the make file technique ... I made .a file. But when I have that library file in my project and include .h file in my c code. I got a compile error. "c:\winavr-20070525\bin\..\lib\gcc\avr\4.1.2\..\..\..\..\avr\bin\ld.exe: cannot find -lAdd"
Please help
 

From memory, I think you also need a capital -L, to indicate the path where the library is stored.

EDIT: actually, looking at your output, it looks like as if it didn't recognise '-l' at all. Not sure why.

Anyway, as mentioned by others, the reasons to want to do this for microcontroller software are
slim (never needed to do this in hundreds of programs). It's not like a PC where a library can be
reused by different software on the fly. You always know if your microcontroller app needs it or not.
It would be done for a microcontroller if you didn't want to distribute source code, i.e. if are you
planning to sell library code.
 
Last edited:
I have tried the make file technique ... I made .a file. But when I have that library file in my project and include .h file in my c code. I got a compile error. "c:\winavr-20070525\bin\..\lib\gcc\avr\4.1.2\..\..\..\..\avr\bin\ld.exe: cannot find -lAdd"

Typically you should add the prefix "lib" to an archive file:


Instead of:


Are you attempting to compile using command line or an IDE?

If an IDE, have you added the archive file to the Use Link Objects in the Project Configuration as well as ensuring an appropriate library search path has been added?

BigDog
 
Hi thanks a lot for your support. It is working, I have to add LibAdd.a

Thanks a lot to all
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top