0

I am using Libtool and the other GNU Autotools (Autoconf, Automake, etc.) to build a shared library. My library has a dependency on another library (hwloc). I allow the user to specify a custom path for hwloc at configuration (the following is in configure.ac):

# Check for hwloc
AC_ARG_WITH([hwloc], [AS_HELP_STRING([--with-hwloc[[=DIR]]], [Location of the hwloc library])])
AS_IF([test "x$with_hwloc" != x],
      [CPPFLAGS="-I$with_hwloc/include $CPPFLAGS"
       LDFLAGS="-L$with_hwloc/lib $LDFLAGS"])
AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([hwloc is a required library])])
AC_SEARCH_LIBS([hwloc_topology_init], [hwloc], [], [AC_MSG_ERROR([hwloc is a required library])])

After doing the build process (./configure --with-hwloc=...; make; make install), my shared library file successfully links with hwloc (ldd libmylib.so):

linux-vdso.so.1 =>  (0x00007ffff331c000)
librt.so.1 => /lib64/librt.so.1 (0x00007fa225c63000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa225a46000)
libhwloc.so.5 => /home/brooks8/bin/hwloc-1.8.1/lib/libhwloc.so.5 (0x00007fa225816000)
libm.so.6 => /lib64/libm.so.6 (0x00007fa225591000)
libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00007fa22523f000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa224eab000)
/lib64/ld-linux-x86-64.so.2 (0x0000003532000000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fa224ca6000)
libz.so.1 => /lib64/libz.so.1 (0x00007fa224a90000)

However, one of my header files includes hwloc. This causes problems when I try and test my library and hwloc is in a non-standard location:

mpicc test.c -I/home/brooks8/bin/mylib/include -L/home/brooks8/bin/mylib/lib -lmylib -o test/test -std=c99 -O3 -g3:

/home/brooks8/bin/mylib/include/include/util.h:14:21: fatal error: hwloc.h: No such file or directory
 #include <hwloc.h>
                    ^

Is there a way to solve this issue without needing to link hwloc when I use my library?

Thank you in advance, and please let me know if I should provide any more information regarding my situation.

Alex Brooks
  • 1,151
  • 1
  • 10
  • 39
  • You might want to look at using [pkg-config](https://www.flameeyes.eu/autotools-mythbuster/pkgconfig/index.html) in conjunction with the autotools. – Brett Hale Apr 09 '14 at 18:18
  • @BrettHale Thank you for the comment. I will check pkg-config out and see if it does what I'm looking for. :) – Alex Brooks Apr 09 '14 at 19:52
  • If your shared library depends on the hwloc library, it's not clear how you'd be able to use yours without linking to hwloc unless all it's using are, say, `#defines` from a header file. – Edward Apr 09 '14 at 20:02
  • @Edward I'm not quite sure I follow. When linking my library to a program, it definitely needs to be linked with hwloc. I just don't want to have to specify the linking. It's like if you configure MPI with a custom path to a library (slurm, knem, nemesis, portals4, etc.). After building MPI with that linking, you don't need to link the other library with your program, just MPI. – Alex Brooks Apr 11 '14 at 13:04

0 Answers0