标签归档:gsl

g++ 调用gsl库

g++ -Wall -I/usr/lib/include -c graymx.cc grayhist.cc sumhist.cc
g++ -Wall -I/usr/lib/include -c grayhist.cc
g++ -Wall -I/usr/lib/include -c sumhist.cc
g++ -static graymx.o grayhist.o sumhist.o -lgsl -lgslcblas -lm -o main.out

Advertisements

gsl 安装以及运行

1.主页
http://www.gnu.org/software/gsl/

2.下载源码及manual
ftp://ftp.gnu.org/gnu/gsl/gsl-1.7.tar.gz
http://www.gnu.org/software/gsl/manual/gsl-ref.ps.gz

3.编译安装
(我用的是FC4)
./configure –diable-shared
make
make install

4.测试
4.1写个testgsl.c:
#include stdio.h;
#include gsl/gsl_sf_bessel.h;

int main(void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0(x);
printf(“J0(%g) = %.18e\n”,x,y);
return 0;
}

4.2编译
gcc -Wall -c testgsl.c

4.3链接
gcc -o testgsl testgsl.o -lgsl -lgslcblas -lm

4.4运行
./testgsl
输出:
J0(5) = -1.775967713143382920e-01

gcc + gsl 编译c文件

gcc -I/usr/lib/include -c test1.c
gcc -L/usr/lib64 test1.o -lgsl -lgslcblas -lm

# g++ -I/usr/lib/include -c main.cpp
[root@localhost test1]# gcc -I/usr/lib/include -c getmin.cpp
[root@localhost test1]# g++ -I/usr/lib/include -c grayhist.cpp
[root@localhost test1]# g++ -I/usr/lib/include -c sumhist.cpp

g++ -static main.o grayhist.o sumhist.o-lgsl -lgslcblas -lm -o main.out

2.3 Shared Libraries

To run a program linked with the shared version of the library the operating system must be able to locate the corresponding .so file at runtime. If the library cannot be found, the following error will occur:

$ ./a.out
./a.out: error while loading shared libraries:
libgsl.so.0: cannot open shared object file: No such
file or directory

To avoid this error, define the shell variable LD_LIBRARY_PATH to include the directory where the library is installed.

For example, in the Bourne shell (/bin/sh or /bin/bash), the library search path can be set with the following commands:

$ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
$ export LD_LIBRARY_PATH
$ ./example

In the C-shell (/bin/csh or /bin/tcsh) the equivalent command is,

% setenv LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH

The standard prompt for the C-shell in the example above is the percent character `%’, and should not be typed as part of the command.

To save retyping these commands each session they should be placed in an individual or system-wide login file.

To compile a statically linked version of the program, use the -static flag in gcc,

$ gcc -static example.o -lgsl -lgslcblas -lm