How to link our rountines to libc.a

Posted on 2005-04-27
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.

Shajith Chandran
Question by:shajithchandran
    LVL 45

    Expert Comment

    Hi shaj,

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

    LVL 5

    Author Comment

    No actually I using AIX. We don't have ldconfig on AIX.
    LVL 22

    Expert Comment

    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.
    LVL 61

    Accepted Solution

    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 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
    LVL 23

    Assisted Solution

    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.

    LVL 61

    Expert Comment

    there are other ways to overload standard functions

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    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 and use pointers 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.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now