1

I have written a C program that consists of a number of files, and uses APR (http://apr.apache.org) - it includes its headers and I would prefer dynamic linking of its libraries.

My problem is that currently I hard-code both the paths to APR headers as set up at my development site and the paths of the static APR library I have found.

This is what my Makefile looks like (i renamed some bits):

my_program: file1.c file2.c file3.c file4.c file5.c file6.c file7.c
    @rm -f $@
    $(CC) -std=c99 -pedantic -D_POSIX_C_SOURCE -I/usr/local/include/apache -L/usr/local/lib -lapr-1 $(CFLAGS) $^ -o $@

Obviously the name of the APR static library file is libapr-1.a, but I also have libapr-1.so and libapr-1.so.0 and even libapr-1.la which I am not even sure what is. So, in effect, I suspect that right now I am linking to APR statically. Aside from my goal of a respectable build system, I would like to link to APR dynamically.

Is there a common practice for me to set up an automated build that will work not only for me now, but also is flexible enough for others to build my program? I smell the proximity of the autotools, but I have absolutely zero experience with them, and would like for now to settle for the next best thing. What options do I have?

Armen Michaeli
  • 8,625
  • 8
  • 58
  • 95

1 Answers1

1

By default linker will pickup shared library (.so) and if it not found static library (.a). So when you pass to linker -lapr-1 it will exectly what you want.

To ensure that your binrary indeed will use shared library run:

ldd your_binary

You should see apr library in output list.

dimba
  • 26,717
  • 34
  • 141
  • 196