⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usage.texi

📁 GNU Scientific Library,C语言开发的数值方面的函数库
💻 TEXI
📖 第 1 页 / 共 2 页
字号:
@cindex standards conformance, ANSI C@cindex ANSI C, use of@cindex C extensions, compatible use of@cindex compatibilityThis chapter describes how to compile programs that use GSL, andintroduces its conventions.  @menu* An Example Program::          * Compiling and Linking::       * Shared Libraries::            * ANSI C Compliance::           * Inline functions::            * Long double::                 * Portability functions::       * Alternative optimized functions::  * Support for different numeric types::  * Compatibility with C++::      * Aliasing of arrays::          * Thread-safety::               * Code Reuse::                  @end menu@node   An Example Program@section An Example ProgramThe following short program demonstrates the use of the library bycomputing the value of the Bessel function @math{J_0(x)} for @math{x=5},@example@verbatiminclude examples/intro.c@end example@noindentThe output is shown below, and should be correct to double-precisionaccuracy,@example@verbatiminclude examples/intro.out@end example@noindentThe steps needed to compile this program are described in the followingsections.@node Compiling and Linking@section Compiling and Linking@cindex compiling programs, include paths@cindex including GSL header files@cindex header files, includingThe library header files are installed in their own @file{gsl}directory.  You should write any preprocessor include statements with a@file{gsl/} directory prefix thus,@example#include <gsl/gsl_math.h>@end example@noindentIf the directory is not installed on the standard search path of yourcompiler you will also need to provide its location to the preprocessoras a command line flag.  The default location of the @file{gsl}directory is @file{/usr/local/include/gsl}.  A typical compilationcommand for a source file @file{example.c} with the GNU C compiler@code{gcc} is,@example$ gcc -Wall -I/usr/local/include -c example.c@end example@noindentThis results in an object file @file{example.o}.   The defaultinclude path for @code{gcc} searches @file{/usr/local/include} automatically sothe @code{-I} option can be omitted when GSL is installed in its defaultlocation.@cindex compiling programs, library paths@cindex linking with GSL libraries@cindex libraries, linking withThe library is installed as a single file, @file{libgsl.a}.  A sharedversion of the library is also installed on systems that support sharedlibraries.  The default location of these files is@file{/usr/local/lib}.  If this directory is not on the standard searchpath of your linker you will also need to provide its location as acommand line flag.To link against the library you need to specifyboth the main library and a supporting @sc{cblas} library, whichprovides standard basic linear algebra subroutines.  A suitable@sc{cblas} implementation is provided in the library@file{libgslcblas.a} if your system does not provide one.  The followingexample shows how to link an application with the library,@example$ gcc -L/usr/local/lib example.o -lgsl -lgslcblas -lm@end example@noindentThe default library path for @code{gcc} searches @file{/usr/local/lib}automatically so the @code{-L} option can be omitted when GSL isinstalled in its default location.The following command line shows how you would link the same applicationwith an alternative blas library called @file{libcblas},@example$ gcc example.o -lgsl -lcblas -lm@end example@noindentFor the best performance an optimized platform-specific @sc{cblas}library should be used for @code{-lcblas}.  The library must conform tothe @sc{cblas} standard.  The @sc{atlas} package provides a portablehigh-performance @sc{blas} library with a @sc{cblas} interface.  It isfree software and should be installed for any work requiring fast vectorand matrix operations.  The following command line will link with the@sc{atlas} library and its @sc{cblas} interface,@example$ gcc example.o -lgsl -lcblas -latlas -lm@end example@noindentFor more information see @ref{BLAS Support}.The program @code{gsl-config} provides information on the local versionof the library.  For example, the following command shows that thelibrary has been installed under the directory @file{/usr/local},@example$ gsl-config --prefix/usr/local@end example@noindentFurther information is available using the command @code{gsl-config --help}.@node Shared Libraries@section Shared Libraries@cindex shared libraries@cindex libraries, shared@cindex LD_LIBRARY_PATHTo run a program linked with the shared version of the library it may benecessary to define the shell variable @code{LD_LIBRARY_PATH} to includethe directory where the library is installed.  For example, in theBourne shell (@code{/bin/sh} or @code{/bin/bash}), the library path can be setwith the following commands:@example$ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH $ export LD_LIBRARY_PATH$ ./example@end example@noindentIn the C-shell (@code{/bin/csh} or @code{/bin/tcsh}) the equivalentcommand is,@example% setenv LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH@end example@noindentThe standard prompt for the C-shell in the example above is the percentcharacter @samp{%}, and should not be typed as part of the command.To save retyping these commands each session they should be placed in anindividual or system-wide login file.To compile a statically linked version of the program, use the@code{-static} flag in @code{gcc},@example$ gcc -static example.o -lgsl -lgslcblas -lm@end example@node ANSI C Compliance@section ANSI C ComplianceThe library is written in ANSI C and is intended to conform to the ANSIC standard.  It should be portable to any system with a working ANSI Ccompiler.The library does not rely on any non-ANSI extensions in the interface itexports to the user.  Programs you write using GSL can be ANSIcompliant.  Extensions which can be used in a way compatible with pureANSI C are supported, however, via conditional compilation.  This allowsthe library to take advantage of compiler extensions on those platformswhich support them.When an ANSI C feature is known to be broken on a particular system thelibrary will exclude any related functions at compile-time.  This shouldmake it impossible to link a program that would use these functions andgive incorrect results.To avoid namespace conflicts all exported function names and variableshave the prefix @code{gsl_}, while exported macros have the prefix@code{GSL_}.@node Inline functions@section Inline functions@cindex inline functions@cindex HAVE_INLINEThe @code{inline} keyword is not part of ANSI C and the library does notexport any inline function definitions by default. However, the libraryprovides optional inline versions of performance-critical functions byconditional compilation.  The inline versions of these functions can beincluded by defining the macro @code{HAVE_INLINE} when compiling anapplication.@example$ gcc -Wall -c -DHAVE_INLINE example.c@end example@noindentIf you use @code{autoconf} this macro can be defined automatically.  Ifyou do not define the macro @code{HAVE_INLINE} then the slowernon-inlined versions of the functions will be used instead.Note that the actual usage of the inline keyword is @code{externinline}, which eliminates unnecessary function definitions in @sc{gcc}.If the form @code{extern inline} causes problems with other compilers astricter autoconf test can be used, see @ref{Autoconf Macros}.@node Long double@section Long double@cindex long doubleThe extended numerical type @code{long double} is part of the ANSI C

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -