?
Solved

How to link our rountines to libc.a

Posted on 2005-04-27
8
Medium Priority
?
626 Views
Last Modified: 2008-01-09
Hello experts,
How can I link my library to standard libc.a.
I have a library which has the definition of some of the standard input/output functions. I would like to link this library to libc.a such that when ever an application make a call to any of this rountines, it should be statisfied from my library.That is my routines should over ride the standard library functions. The standard functions are defined in shr.o in libc.a.

Please someoone help be in this. This is quite urgent.

Thanks
Shajith Chandran
0
Comment
Question by:shajithchandran
6 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 13876319
Hi shaj,

I am assuming that you are on a Linux box. look into man pages of ldconfig ... You need to edit the /etc/ld.so.conf file to add your path as first component and then run ldconfig.

Cheers!
sunnycoder
0
 
LVL 5

Author Comment

by:shajithchandran
ID: 13877277
No actually I using AIX. We don't have ldconfig on AIX.
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 13878587
I think you will need to replace your libc.a with a modified version containing your replacement routines.  This is kind of a brute force way to do it, but it ought to work pretty well.

1.  Make a backup copy of libc.a in case you mess things up.
2.  Use nm on libc.a to find out which .o files contain the functions you would like to replace.
3.  Compile your replacement functions into some .o files.
4.  Use ar to remove the old .o files from libc.a.
5.  Use ar to add your new .o files into libc.a

It would be better if you could take your .o files, put them into your own library, then reconfigure your compiler to go for your library before going for the system libc.a.  I don't know if this is possible for your AIX compiler.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 62

Accepted Solution

by:
gheist earned 1000 total points
ID: 13879846
easiest is to include these functions in different library under different names, since altering libc may carry unwanted consequences.

to relink libc you have to use ar to repackage .a file
then use ld or cc to link libc.so back

best if target files are not in /usr/lib, but in some other place, which can be added to your application using LIBPATH variable.

such relinking has to be done after applying any patch to system
0
 
LVL 23

Assisted Solution

by:brettmjohnson
brettmjohnson earned 1000 total points
ID: 13882971
The easiest way is to include your functions/library in the link list BEFORE libc.a (typically last anyway).
Your definitions of functions will then override those in the standard library.

0
 
LVL 62

Expert Comment

by:gheist
ID: 13883348
there are other ways to overload standard functions
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question