A Developer's Diary

Feb 4, 2008

Finding dependent libraries on Aix

Finding dependent libraries on AIX.

Method 1.
This is a small dlopen test program "dltest.cpp"

//File: dltest.cpp

#include <stdio.h>
#include <dlfcn.h>

int main()
{
    char str[20] = {0};
    printf("\nEnter path to the Library to be loaded = ");
    scanf("%s", str);

    void *libhandle = dlopen(str, RTLD_LAZY);
    if(NULL == libhandle)
    {
        printf("\nUnable to load library. Error: %s\n", dlerror());
    }
    else
    {
        printf("\nSuccessfully loaded library %s\n", str);
    }

    return 0;
}

Compile the above program using:
xlC_r -brtl -o out dltest.cpp

Executing the file ./out will give the dlerror() output and the missing dependent libraries.

Method 2.
A dirty way to search.

ldd filename


It will not list the libraries which are present. It simply displays "Cannot Find" all libraries which are dependent and not found.
More conveniently

truss ldd somefilename.so >> output.txt 2>&1

Check the output.txt and search for libs which are not there.