📄 autoconf.texi
字号:
@cindex autoconf, using with GSLFor applications using @code{autoconf} the standard macro@code{AC_CHECK_LIB} can be used to link with the library automaticallyfrom a @code{configure} script. The library itself depends on thepresence of a @sc{cblas} and math library as well, so these must also belocated before linking with the main @code{libgsl} file. The followingcommands should be placed in the @file{configure.in} file to performthese tests,@exampleAC_CHECK_LIB(m,main)AC_CHECK_LIB(gslcblas,main)AC_CHECK_LIB(gsl,main)@end example@noindentIt is important to check for @code{libm} and @code{libgslcblas} before@code{libgsl}, otherwise the tests will fail. Assuming the librariesare found the output during the configure stage looks like this,@examplechecking for main in -lm... yeschecking for main in -lgslcblas... yeschecking for main in -lgsl... yes@end example@noindentIf the library is found then the tests will define the macros@code{HAVE_LIBGSL}, @code{HAVE_LIBGSLCBLAS}, @code{HAVE_LIBM} and addthe options @code{-lgsl -lgslcblas -lm} to the variable @code{LIBS}.The tests above will find any version of the library. They are suitablefor general use, where the versions of the functions are not important.An alternative macro is available in the file @file{gsl.m4} to test fora specific version of the library. To use this macro simply add thefollowing line to your @file{configure.in} file instead of the testsabove:@exampleAM_PATH_GSL(GSL_VERSION, [action-if-found], [action-if-not-found])@end example@noindentThe argument @code{GSL_VERSION} should be the two or three digit@sc{major.minor} or @sc{major.minor.micro} version number of the releaseyou require. A suitable choice for @code{action-if-not-found} is,@exampleAC_MSG_ERROR(could not find required version of GSL)@end example@noindentThen you can add the variables @code{GSL_LIBS} and @code{GSL_CFLAGS} toyour Makefile.am files to obtain the correct compiler flags.@code{GSL_LIBS} is equal to the output of the @code{gsl-config --libs}command and @code{GSL_CFLAGS} is equal to @code{gsl-config --cflags}command. For example,@examplelibgsdv_la_LDFLAGS = \ $(GTK_LIBDIR) \ $(GTK_LIBS) -lgsdvgsl $(GSL_LIBS) -lgslcblas@end example@noindentNote that the macro @code{AM_PATH_GSL} needs to use the C compiler so itshould appear in the @file{configure.in} file before the macro@code{AC_LANG_CPLUSPLUS} for programs that use C++.To test for @code{inline} the following test should be placed in your@file{configure.in} file,@exampleAC_C_INLINEif test "$ac_cv_c_inline" != no ; then AC_DEFINE(HAVE_INLINE,1) AC_SUBST(HAVE_INLINE)fi@end example@noindentand the macro will then be defined in the compilation flags or byincluding the file @file{config.h} before any library headers. The following autoconf test will check for @code{extern inline},@smallexamplednl Check for "extern inline", using a modified versiondnl of the test for AC_C_INLINE from acspecific.mtdnlAC_CACHE_CHECK([for extern inline], ac_cv_c_extern_inline,[ac_cv_c_extern_inline=noAC_TRY_COMPILE([extern $ac_cv_c_inline double foo(double x);extern $ac_cv_c_inline double foo(double x) @{ return x+1.0; @};double foo (double x) @{ return x + 1.0; @};], [ foo(1.0) ],[ac_cv_c_extern_inline="yes"])])if test "$ac_cv_c_extern_inline" != no ; then AC_DEFINE(HAVE_INLINE,1) AC_SUBST(HAVE_INLINE)fi@end smallexampleThe substitution of portability functions can be made automatically ifyou use @code{autoconf}. For example, to test whether the BSD function@code{hypot} is available you can include the following line in theconfigure file @file{configure.in} for your application,@exampleAC_CHECK_FUNCS(hypot)@end example@noindentand place the following macro definitions in the file@file{config.h.in},@example/* Substitute gsl_hypot for missing system hypot */#ifndef HAVE_HYPOT#define hypot gsl_hypot#endif@end example@noindentThe application source files can then use the include command@code{#include <config.h>} to substitute @code{gsl_hypot} for eachoccurrence of @code{hypot} when @code{hypot} is not available.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -