Technical article 100786

How do I create and debug dynamic library functions?

OpenServer 5.0.0

Written · Last revised

Problem

How can I create and debug dynamic library functions?

Solution

This example procedure details creation of a debuggable dynamic library function:

1. Create a file called dyfunc.c containing a (very simple) example:

#include        <stdio.h>
dyfunc()
{
    printf("Dynamic function called\n");
}

2. Create the debuggable dynamic library that contains the above function using cc(CP):

$ cc -g -dy -Kpic -G -o libdyfunc.so dyfunc.c

3. Create a program called main.c that calls the dynamic function:

extern void dyfunc();
main()
{
    dyfunc();
}
4. Compile this using cc(CP):
$ cc -g -dy -Kpic -o main main.c -L. -ldyfunc

5. Set the environment variable "LD_LIBRARY_PATH" to the current working directory. For sh(C) and ksh(C), use the following:

$ LD_LIBRARY_PATH=`pwd` export LD_LIBRARY_PATH

"main" should now run, and a source-level debugger (for example, dbXtra(CP)) can be used to debug it.

See also

cc(CP), ar(CP), dbx(CP), dbXtra(CP)

From the Xinuos technical article database, record 100786. Reproduced with permission. The original is at www.sco.com/ta/100786, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.