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

📄 usage.texi

📁 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without ev
💻 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::               * Deprecated Functions::        * 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 actually be omitted when GSL is installed in its default location.@menu* Linking programs with the library::  * Linking with an alternative BLAS library::  @end menu@node Linking programs with the library@subsection Linking programs with the library@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 @file{libgsl.so} is also installed on systemsthat support shared libraries.  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.@node Linking with an alternative BLAS library@subsection Linking with an alternative BLAS libraryThe following command line shows how you would link the same applicationwith an alternative @sc{cblas} 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}.@comment  The program @code{gsl-config} provides information on the local version@comment  of the library.  For example, the following command shows that the@comment  library has been installed under the directory @file{/usr/local},@comment  @example@comment  $ gsl-config --prefix@comment  /usr/local@comment  @end example@comment  @noindent@comment  Further 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 theoperating system must be able to locate the corresponding @file{.so}file at runtime.  If the library cannot be found, the following errorwill occur:@example$ ./a.out ./a.out: error while loading shared libraries: libgsl.so.0: cannot open shared object file: No such file or directory@end example@noindentTo avoid this error, define the shell variable @code{LD_LIBRARY_PATH} toinclude the directory where the library is installed.For example, in the Bourne shell (@code{/bin/sh} or @code{/bin/bash}),the library search path can be set with 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 (C89).  It should be portable to any system with a workingANSI C compiler.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 the original ANSI C standard(C89) and the library does not export any inline function definitions bydefault. However, the library provides optional inline versions ofperformance-critical functions by conditional compilation.  The inlineversions of these functions can be included by defining the macro@code{HAVE_INLINE} when compiling an application,@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}.

⌨️ 快捷键说明

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