Libtool:在头文件中维护库依赖项

时间:2014-04-09 16:27:32

标签: shared-libraries autotools libtool

我使用Libtool和其他GNU Autotools(Autoconf,Automake等)来构建共享库。我的库依赖于另一个库(hwloc)。我允许用户在配置时指定hwloc的自定义路径(以下内容位于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])])

完成构建过程(./configure --with-hwloc=...; make; make install)后,我的共享库文件成功链接到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)

但是,我的一个头文件包含hwloc。当我尝试测试我的库并且hwloc位于非标准位置时,这会导致问题:

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>
                    ^

有没有办法解决这个问题,而不需要在我使用我的库时链接hwloc?

提前感谢您,如果我应该提供有关我的情况的更多信息,请告诉我。

0 个答案:

没有答案