You can build the strings into your executable for the various autoconfigured locations that you might want to look in. This is more or less what programs such as GCC do.
For example, GCC 4.3.3 on my machine was compiled under /work5/tmp and configured for installation in /usr/gcc/v4.3.3, and it contains (amongst many others) the strings:
/usr/ccs/bin/
/usr/ccs/lib/
/usr/gcc/v4.3.3
/usr/gcc/v4.3.3/bin/
/usr/gcc/v4.3.3/lib
/usr/gcc/v4.3.3/lib/gcc/
/usr/gcc/v4.3.3/libexec/gcc/
/usr/gcc/v4.3.3/share/locale
/usr/gnu/include
/usr/include
/usr/include/iso
/usr/include/sys
/usr/lib/
/usr/lib/ld.so.1
/usr/libexec/gcc/
/usr/local/share/bison
/usr/tmp
/var/tmp
/var/tmp/
/work5/tmp/gcc-4.3.3-obj/./prev-gcc/include
/work5/tmp/gcc-4.3.3-obj/gcc
/work5/tmp/gcc-4.3.3-obj/intl
/work5/tmp/gcc-4.3.3-obj/libiberty
/work5/tmp/gcc-4.3.3-obj/sparc-sun-solaris2.10/libgcc
A comment says: "That's what I'm trying to figure out how to do?"
There are numerous ways. Part of the answer is knowing which names you need. If you look at the autoconfigure output, there are names such as prefixdir and pkglibdir in the makefile. You could add those to the C compiler lines:
DFLAG1 = -DPKGLIBDIR='"$(pkglibdir)"'
and add DFLAG1 to your CFLAGS. Repeat ad nauseam...
The code inside your program can then do things like:
static const char *libdirs_to_search[] =
{
...
#ifdef PKGLIBDIR
PKGLIBDIR,
#endif /* PKGLIBDIR */
};
A cleaner way to do it is to modify the generated config.h file and the configure code so that the directories you are interested in are defined in the config.h file, rather than in the makefile.