.a files from libraries

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

.a files from libraries

1,794 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tanmay on Mon Feb 04 20:52:02 MST 2013
Hi all,
   I have created a project and some libraries for the same.
I can include those libraries through project properties but can I just include just .a file of the those libraries???
n HOW???


Thank you........
0 Kudos
Reply
10 Replies

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wrighflyer on Wed Feb 06 09:41:50 MST 2013

Quote: CodeRedSupport
The following FAQ covers the use of -ffunction-sections and --gc-sections:

http://support.code-red-tech.com/CodeRedWiki/UnusedSectionElimination

Regards,
CodeRedSupport


You might want to add a section to that about building libraries. This modern trend of putting multiple functions in single library component source files means that -ffunction-sections must be used when the library is built and for the user it's absolutely vital that -gc-sections is used in their link.
0 Kudos
Reply

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Feb 06 07:54:15 MST 2013
The following FAQ covers the use of -ffunction-sections and --gc-sections:

http://support.code-red-tech.com/CodeRedWiki/UnusedSectionElimination

Regards,
CodeRedSupport
0 Kudos
Reply

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wrighflyer on Wed Feb 06 07:31:42 MST 2013

Quote: tanmay
But I didnt get the quoted part.
What exactly it means???
Thnx again...

Well say you write some libary code:
void foo(void) { }  void bar(void) { }
You have two options. You could put each of those into separate .c files. Then one fill compile from foo.c to foo.o and the other will compile from bar.c to bar.o. You then create the library with 
arm-ar rcs libstuff.a foo.o bar.o
and then the program that uses foo() links with libstuff.a (-lstuff). The linker will only pull the contents of foo.o into the final program so you don't get a copy of bar() you don't want or need.  However if you follow the modern trend of just putting all the library functions in a single file (stuff.c) and you just compile that to make a stuff.o then create a library with:
arm-ar rcs libstuff.a stuff.o
then when you come to link with foo() the linker cannot break foo() and bar() apart and you get both built into the program even though you didn't want bar(). The solution is to build stuff.c with the option -ffunction-sections. Now the stuff.o (and hence libstuff.a) won't just have a single section called .text with foo() and bar() in it. It will have a section called .text.foo with foo() in it and a section called .text.bar with bar() in it.  Now when you link with libstuff.a you also give the option -gc-sections (gc=garbage collect = get rid of stuff that's not needed). As both foo() and bar() come from the single stuff.c/o the linker will initially add them both to the linked image. But when it does the garbage collection which merges .text.foo and .text.bar into the final .text it sees that while foo() in .text.foo is used the function bar() in .text.bar is not. So it throws away that section/code and only .text.foo makes it into the final file.  So you have two ways to split the functions in a library. The "old" way that we all used before -gc-sections (etc) existed and put each function in a separate .c file (and hence .o file in the .a) or the "modern" way which is to not care about how you split the functions in the source but build it with -ffunction-sections so the built code has each function separated anyway then link with gc-sections which says "discard what's not used even if it came from one of the .o files".  There is a further issue with all this that I highlighted in another thread here to do with interrupt handler code in libraries that uses the "common names" that cause it to be linked as a handler. It over-rides the weak links in the vector table and can lead to code getting linked in when you don't want it. But this is an advanced topic so don't worry about it just yet.  WF1903
0 Kudos
Reply

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tanmay on Wed Feb 06 05:33:37 MST 2013
Unless your libs have been built with each function in a separate source file you will want to ensure it was built with -ffunction-sections and when the lib is used the linker should be given -gc-sections as the other part of that mechanism. This will ensure that only the called functions are linked into the project.[/QUOTE]


Thanx wrighflyer...

But I didnt get the quoted part.
What exactly it means???
Thnx again...
0 Kudos
Reply

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frame on Tue Feb 05 07:37:20 MST 2013

Quote: tanmay
...
I dont want any one to see those library codes...
..



[B][FONT=Courier New]objdump -d  yourlib.a
[/FONT][/B]
0 Kudos
Reply

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tarik1985 on Tue Feb 05 07:33:25 MST 2013
thank you very much
0 Kudos
Reply

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Feb 05 06:41:26 MST 2013
:confused:

http://www.support.code-red-tech.com/CodeRedWiki/LibraryProjects

:)

Also 'Smart Update' is very useful therfore :eek:

http://www.support.code-red-tech.com/CodeRedWiki/StaticLibrarySupportv4?highlight=%28smart%29|%28upd...
0 Kudos
Reply

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wrighflyer on Tue Feb 05 06:09:56 MST 2013
Assuming you have created libsomething.a then just add a -lsomething to the end of the linker command. The linker automatically adds "lib" to the start and ".a" to the end when it searches for the file. If the .a file is not in the same directory also use the -L linker options to tell it what directory to look in such as "-L"C:\mylibs\uart" -luart" which would find a libuart.a in C:\mylibs\uart\.

Unless your libs have been built with each function in a separate source file you will want to ensure it was built with -ffunction-sections and when the lib is used the linker should be given -gc-sections as the other part of that mechanism. This will ensure that only the called functions are linked into the project.
0 Kudos
Reply

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tanmay on Tue Feb 05 03:52:47 MST 2013
how do i use library in my application program then??
I dont want any one to see those library codes...

Please tell if anyone knows...
0 Kudos
Reply

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tanmay on Mon Feb 04 21:58:23 MST 2013
i dont want to add full library project there.
is it possible to use just .a file?????


Plz Help.....
0 Kudos
Reply