Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
midea31
PostPosted: Jul 17, 2012 - 01:49 AM
Hangaround


Joined: Jul 22, 2011
Posts: 172


Hi All,

I have been using Peter Fleury's lcd library for quite some time now. And I am doing my 3rd app with his library. But until this time, I still include lcd.h and lcd.c in my projects.

I was wondering if I could just include the header file, kind of like how we use _delay_ms(). I mean we just include <util/delay.h> right?

I have been doing some reading and I "think" this has something to do with .o files? And with the "linker" but I am quite confused so please help me?

Also, I am using AS4 and I have been familiarizing myself with AS6(as they say it is already bug-free?).
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Jul 17, 2012 - 01:59 AM
10k+ Postman


Joined: Nov 17, 2004
Posts: 14684
Location: Vancouver, BC

Quote:
I mean we just include <util/delay.h> right?
But all of the code is in that file or other .h files that that file includes. With the lcd files, all of the code is in the .c file. So if you don't include lcd.c, you won't have any of the actual code.
Quote:
I have been doing some reading and I "think" this has something to do with .o files?
The .o files are built from the .c files. You could create .a files, but you would have to have a separate .a file for each AVR that you use. And you would still have to link to those files, so it really wouldn't gain you anything except a second or two of compilation time.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Jul 17, 2012 - 11:00 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21397
Location: Lund, Sweden

To answer the technical question as such:

Building an app is done in these steps:

App-1) Source code (.c) is compiled into object code (.o). Each source file is compiled separately (unless you apply special options, which we will not cover here).

App-2) All object files are combined together into one file (.elf). (Had this been on e.g. a U*nix system, this would be the executable.) This is done by the linker, and apart from taking object files, it can also get it's input from libraries (.a). Such libraries are in essence just a glued-together collection of object files and a TOC.

App-3) For AVRs, there is an additional step, taking the .elf and extracting/converting the contents into separate files with data destined for the different AVR memories. The obvious example is creating a .hex file with the program code - destined for flash. But there can also be produced files with EEPROM contents, or values for programming the fuses. The program that does this is called "avr-objcopy".

Now on to libraries:

This starts out just as above..

Lib-1) Source code (.c) is compiled into object code (.o).

Then...

Lib-2) These object files are combined into an "archive" (thus the .a file extension). The program that does this is "as" (in e.g. WinAVR and AVR Toolchain it goes under the name "avr-as"). Be sure to make the name of the library start with "lib" (see below) and it's file extension should be .a .

Your library is done!

You can now use it by specifying it to the linker in an App-2 stage. On a command line you would use the -l switch to name the library to use. When you specify the library name do not incorporate the initial "lib", nor the .a extension. So, to link with libmyutil.a you would simply say -lmyutil.

This is one of my most non-favourite things with the GCC/binutils tool chain. I am totally comfortable with the extension defaulting to .a, but I hate the default "lib" prefix.

If you want to get all the nitty-gritty detail of the process, I would recommend:
1) A study of the MFile utility's template makefile
2) The GNU documentation on GCC and "ar" close by

You could also set up a library project in e.g. Atmel Studio 6 (it has a template for that), and then look at the makefile it generates. I would suspect it to be less fitting for reading by a human than e.g. the MFile template malefile.

HTH!


Last edited by JohanEkdahl on Jul 17, 2012 - 11:02 AM; edited 1 time in total
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
WrightFlyer
PostPosted: Jul 17, 2012 - 11:01 AM
Hangaround


Joined: Sep 06, 2007
Posts: 130


Even the "second or two of compilation time" really means one or two seconds the first time lcd.c is compiled to lcd.o because after that it's unlikely to change so won't be compiled again and there's even an argument that the linker can link a .o fractionally quicker than a .a!
 
 View user's profile Send private message  
Reply with quote Back to top
Jepael
PostPosted: Jul 17, 2012 - 11:02 AM
Raving lunatic


Joined: May 24, 2004
Posts: 6229
Location: Tampere, Finland

And if I recall correctly, the Fleury LCD code is configured by modifying the .h file, so every time you change the .h file because IO pins are differently, you have to recompile the .c file into library again before the changes take effect.

It is not worth it to make it into a "real" library, keep it as a source file.

What you could do is keep the .c source file in some common place, and have customized .h file for each project. Remember to add the .c source into makefile (or project if you use some GUI) so it gets compiled into object file before linking the binary, preferably in the project folder, not in the library folder.

Code:

C:\Projects\MyProject1
C:\Projects\MyProject2
C:\Projects\FleuryLib
 
 View user's profile Send private message  
Reply with quote Back to top
midea31
PostPosted: Jul 18, 2012 - 01:01 AM
Hangaround


Joined: Jul 22, 2011
Posts: 172


i am not after compilation speed or anything like that, i was just wondering if there was some other (better?) way of doing things.

since i am using Fleury's "library" but i am not actually using it as a "library" per se.

@johan,
thank you for the explanation, i have not digested all of it yet. i will do a bit more reading.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jul 18, 2012 - 02:04 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69423
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

i was just wondering if there was some other (better?) way of doing things.

Pre compiled libs work for things like sin/cos/tan or printf/strcpy/itoa/etc. because there's nothing particularly machine specific about them (though even for those there are about 10 different versions of .a as some processors have MUL, some don't, some have JMP/CALL while some only have RJMP/RCALL and so on). But for anything that uses the hardware and needs configuration (like which pins an LCD lib uses) there is no advantage in a pre-compiled lib and in fact it's would be very tricky to have it dynamically adjust to different pin layouts at run time - so those decisions are better made at compile time.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
midea31
PostPosted: Jul 19, 2012 - 01:00 AM
Hangaround


Joined: Jul 22, 2011
Posts: 172


@clawson
ah.. i understand. thank you.
i have just been doing simple apps and i made it a point to use the same pins for the lcd.

@johan
i have tried as6 library project, works like a charm!
(i am not knowledgable enough to try to invoke gcc on the command line yet, its still the gui for me - thank you very much)

@jepael
i see your point, thanks. i think this is the way to go for me.
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Jul 19, 2012 - 08:31 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21397
Location: Lund, Sweden

Quote:
i am not knowledgable enough to try to invoke gcc on the command line yet, its still the gui for me - thank you very much

That's OK, I didn't write it as an instruction on how to do it by hand. But you should understand what is involved and running when you press that build button in your IDE - THAT is why I wrote it.

And you did say
Quote:
I "think" this has something to do with .o files? And with the "linker" but I am quite confused so please help me?

and the best help I could think of at the moment was to straighten out the processes.

You're most welcome! Very Happy
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits