NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Support Forum » Create a library
November 09, 2013 by dvdsnyd |
Hi all! Hope everyone that is still utilizing these forums is doing well. It has been a while again...man life just doesn't seem to slow down much right now. Anyways, I have been looking at creating my own library for some of the sensors/devices that I have written code for, ie. BMP085 pressure sensor, EEPROM. However, I have a couple of questions/thoughts. How does one go about building something like the libnerdkits library? Are there any resources that can be found on the subject? I have read through: However, it seems to leave out quite a bit of information. Are there certain requirements, as in is lib a required prefix before the library name? Also, looking at the uart.h and uart.c files in the libnerdkits folder: first, uart.c
And uart.h
Why does the .h file and .c files both have some of the same include files? They both include inttypes and stdio. I thought that the header basically was read and took care of all the include files. Is this not the case? Or is it because two of the prototypes defined in uart.h are declared integers? It just seems redundant. Do I need to "make" the library with a makefile? Or is there a way to do it manually? Does anyone have any advice or a "formula" for making libraries? Again, Thanks for sticking in here, I appreciate all of your help! Dave |
---|---|
November 10, 2013 by Ralphxyz |
Hi Dave, one of the key points from the article is:
That's the one that has caught me in the past. What do you see as missing? Ralph |
November 10, 2013 by Noter |
Putting .c source and .h includes into a common folder does not make a library. It is just a common directory where reusable code may reside. A true library is a file containing precompiled objects. Although there exists both static and dynamic linking, in the world of the nerdkit we deal only with static linking. With a real library, the linker will reference only the library file instead of one or many individual objects. So the libnerdkits directory is just a common directory. It can be named anything you wish as the name doesn't make any difference. Likewise, a library file, typically a .o, can be named anything you wish. It's what's inside that makes the difference. From an organizational perspective it is good to have a common place for reusable code to reside. This is particularly helpful in larger projects with many .c and .h files used by many other .c files. In the tutorial above, Dean is showing a method that helps to organize and manage reusable code. At the very end he says you may want to put the common objects in a library for distribution. His method of organization is not a library, it is just one way to have a common directory for reusable code. Another way is to put all your reusable code in a directory named libnerdkits. It could just as easily be named common or share. |
November 10, 2013 by Noter |
As for the include<avr/whatever>, it doesn't really matter to the compiler how many times they are included because it only uses the first one it comes across. Hard to say why some authors put/leave useless includes into header or source files. |
November 10, 2013 by JKITSON |
NOTER, Thanks for the information. This helped me to understand the naming concept better.. Jim |
November 11, 2013 by dvdsnyd |
Noter, As always you really help me(and everyone else) understand things easier. So, how does one go from just "managing" reusable code in a common directory to a full blown library? (I would imagine some sort of a makefile leading to a .o file correct? Or is it not necessary to go through the trouble? Thanks again for your help! Dave |
November 11, 2013 by Noter |
I was building and using a library for a while but now just directly link the objects again. I don't use a lot of shared code so it doesn't make much difference to me. Usually I just put code for the usart in the program I'm writing because it's just a couple of small functions and it's easier to change them there. I use the avr-gcc util/delay's now and seldom use the lcd display and typically my program has no includes from a common directory. Makes it easier to send it or post it for someone else too. I said above the library was a .o and the name doesn't matter. After a quick review of the documentation I realize I forgot it's a .a and the name must begin with lib. Here's the makefile I used to build the nerdkits library -
Then to use it in a make file this is the rule and recipe I used -
|
Please log in to post a reply.
Did you know that binary numbers use base 2 to represent numbers, and these are important for understanding microcontroller registers? Learn more...
|