Reputation: 103
I'm an autotools beginner, and I can't seem to figure out how to use an external library correctly with autotools.
Here is my directory hierarchy.
.
├── configure.ac
├── Makefile.am
├── README
└── src
(source files)
└── Makefile.am
The library's name is acml_mp
and is, by default, installed in /opt/acml5.3.1/gfortran64/lib
. There is also a directory called /opt/acml5.3.1/gfortran64/include
to include. When I compile without autotools, including the usual compiler flags works fine:
g++ ... -L/opt/acml5.3.1/gfortran64_mp/lib -I/opt/acml5.3.1/gfortran64_mp/include -lacml_mp ...
In configure.ac, I put the command AC_LIB_LINKFLAGS([acml_mp])
which I think only deals with the -lacml_mp
flag.
Basically, the end goal is to have autoconf search for this library, and have the makefile generated by automake include the correct link/include paths when compiling. Finally, when compiling by hand, I always need to modify the environment variable LD_LIBRARY_PATH
using the command
Export LD_LIBRARY_PATH=/opt/acml5.3.1/gfortran64_mp/lib:$LD_LIBRARY_PATH
which, ideally, I would like to avoid having the user do. Apologies if this information exists already, I looked through SO and Google for a few hours to no avail.
Upvotes: 4
Views: 4952
Reputation: 22308
The problem with searching is that /opt/acml5.3.1/gfortran
is never going to be a standard (search) location for libraries (and headers) like /usr/lib
, /usr/local/lib
etc. Probably the best bet is to supply this location explicitly via --with-acml
to configure.
The AC_ARG_WITH
macro is described here. Assuming test "x$with_acml" != xno
, you can try linking a program with AC_LINK_IFELSE
.
AC_LANG_PUSH([C]) # or [Fortran]
ac_save_acml_CPPFLAGS="$CPPFLAGS" # or FCFLAGS instead of CPPFLAGS.
ac_save_acml_LIBS="$LIBS"
ac_acml_CPPFLAGS="-I${with_acml}/include"
ac_acml_LIBS="-L${with_acml}/libs -lacml_mp"
CPPFLAGS+="$ac_acml_CPPFLAGS"
LIBS+="$ac_acml_LIBS"
AC_LINK_IFELSE([AC_LANG_PROGRAM( ... some C or Fortran program ... )],,
AC_MSG_FAILURE([couldn't link with acml]))
AC_LANG_POP
# we *could* stop here... but we might need the original values later.
CPPFLAGS="$ac_save_acml_CPPFLAGS"
LIBS="$ac_save_acml_LIBS"
AC_SUBST(ACML_CPPFLAGS, $ac_acml_CPPFLAGS)
AC_SUBST(ACML_LIBFLAGS, $ac_acml_LIBS)
Assuming you've initialized libtool support with LT_INIT
, you can add the acml library with $(ACML_LIBFLAGS)
to your own libraries in src/Makefile.am
via the LIBADD
variable, or to executables with the LDADD
variable. or <lib>_la_LIBADD
, <prog>_LDADD
respectively.
To compile sources with the $(ACML_CPPFLAGS)
include path, add it to the AM_CPPFLAGS
variable. Or the <prog>_CPPFLAGS
variable.
It's difficult to be specific without knowing how your Makefile.am
is already set up. I know it looks complicated - but it's better to get the infrastructure right the first time. I'll add to the answer if you have further questions.
Upvotes: 5