(转载)Ubuntu 安装GNU Scientific library(GSL)
背景:
Blei的hlda的C语言实现需要使用C语言的科学计算包GSL,因此决定安装。由于在windows下安装极其繁琐,先在Linux上安装之。
系统环境:
gsl安装过程
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
一个是libgslcblas.so,libgsl.so的位置很重要,编译后的文件被扔到了这里,比如 /usr/local/lib;另一个重要的位置是
- #include <stdio.h>
- #include <gsl_rng.h>
- #include <gsl_randist.h>
- int main (int argc, char *argv[])
- {
- /* set up GSL RNG */
- gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937);
- /* end of GSL setup */
- int i,n;
- double gauss,gamma;
- n=atoi(argv[1]);
- for (i=0;i<n;i++)
- {
- gauss=gsl_ran_gaussian(r,2.0);
- gamma=gsl_ran_gamma(r,2.0,3.0);
- printf("%2.4f %2.4f\n", gauss,gamma);
- }
- return(0);
- }
(1)第一反应是直接 gcc gsl_test.c
显示错误是:gsl_test.c:2: fatal error: gsl_rng.h: 没有那个文件或目录
(2)这个错误是说没有找到头文件,然后加上头文件的位置,gcc -I/usr/local/include/gsl gsl_test.c
显示错误是:gsl_test.c:(.text+0x12): undefined reference to `gsl_rng_mt19937' ...
(3)这个错误是说没有找到gsl_rng_mt19937的定义,查看了http://www.daniweb.com/software-development/cpp/threads/289812/cant-link-gsl-properly,这里说需要加上-lgsl,即链接到gsl,找到 libgsl.so.
使用命令:gcc -I/usr/local/include/gsl -lgsl gsl_test.c
(4)显示错误是://usr/local/lib/libgsl.so: undefined reference to `cblas_ctrmv'
查看了http://sourceware.org/ml/gsl-discuss/2003-q2/msg00123.html,是说错误是由于没有链接libgslcblas.so引起的,再加上-lgslcblas可以解决问题。
使用命令:gcc -I/usr/local/include/gsl -lgsl -lgslcblas gsl_test.c。
或者命令:gcc -I/usr/local/include/gsl -L/usr/local/lib -lgsl -lgslcblas gsl_test.c
(5)实测需要以下命令: gcc -I/usr/local/include/gsl gsl_test.c -lgsl -lgslcblas
这个时候出现了产出物a.out。
(5)运行a.out
./a.out 出现错误“段错误”
(6)查看源文件,发现还需要输入参数
./a.out 10
结果是:
0.2678 6.9645
3.3488 1.6894
1.9950 2.1575
-4.7934 6.1648
-0.0782 4.0292
1.7871 11.6031
-2.5931 7.7629
0.3634 1.3344
-1.0965 11.1658
0.0142 3.5412
彻底搞定,done#
转自:http://blog.csdn.net/Waleking/article/details/8265008
由于论文数据处理的需要,需要使用libeemd这个包,需要安装gsl科学库,windows下没有办法,只能转战ubuntu进行科学计算。
GSL(GNU Scientific Library)作为三大科学计算库之一,除了涵盖基本的线性代数,微分方程,积分,随机数,组合数,方程求根,多项式求根,排序等,还有模拟退火,快速傅里叶变换,小波,插值,基本样条,最小二乘拟合,特殊函数等
当然最希望通过命令来安装GSL科学库。
方法一:
GSL源码包提供了以下二进制包:
- gsl-bin:GNU Scientific Library (GSL) -- binary package
- libgsl0-dbg: GNU Scientific Library (GSL) -- debug symbols package
- libgsl0-dev: GNU Scientific Library (GSL) -- development package
- libgsl0ldbl: GNU Scientific Library (GSL) -- library package
终端键入以下命令即可安装:
sudo apt-get install libgsl0ldbl
说明:根据不同的需要选择安装不同的版本,使用 gsl-bin 将会安装所有的内容(gsl - bin 依赖 libgsl0ldbl)
方法二:
ubuntu自己编译源码(使用gsl1.6,windows上太麻烦折腾),解压后进入目录,执行:
./configure
make
make install
这个过程需要几分钟。这里还有一点需要注意的是,执行 make install 时,会自动将动态库和头文件分别拷贝到/usr/local/lib和 /usr/local/include 下面,但如果这两个目录没有写权限,就无法创建此二目录,导致安装失败,此时改用 sudo make install或者手动去赋予权限,便能解决此问题。
说明:折腾一圈还是使用前者成功的。
sudo apt-get install libgsl0-dev
参考
- http://www.lancezhange.com/2014/10/24/gsl-in-practice/
- http://www.cnblogs.com/nju2014/p/5334928.html
(转载)Ubuntu 安装GNU Scientific library(GSL)的更多相关文章
- Ubuntu 安装GNU Scientific library(GSL)
注: 此系列为自己之前所搭建网站内容. 由于论文数据处理的需要,需要使用libeemd这个包,需要安装gsl科学库,windows下没有办法,只能转战ubuntu进行科学计算. GSL(GNU Sci ...
- Visual Stdio 环境下使用 GSL (GNU Scientific Library)
Visual Stdio 环境下使用 GSL (GNU Scientific Library) 经測试.这里的方法不适用于VS2015. * 这篇文章有点过时了.建议从以下网址下载能够在 vs 环境下 ...
- 【C++】GSL(GNU Scientific Library) 的安装及在 Visual Studio 2017 中的使用
GSL 是 GNU 开发并维护的科学计算的库,其中包括: 复数 多项式的根 特殊函数 向量和矩阵 排列 排序 BLAS支持 线性代数 Eigensystems 快速傅立叶变换 正交 随机数 准随机序列 ...
- GNU scientific library
GNU scientific library 是一个强大的C,C++数学库.它涉及的面很广,并且代码效率高,接口丰富.正好最近做的一个项目中用到多元高斯分布,就找到了这个库. GNU scientif ...
- [转载]Ubuntu安装配置 git 服务器和客户端
原文地址:Ubuntu安装配置 git 服务器和客户端作者:ding404 1.配置前准备 服务器:安装ssh server另外还装了gitosis做git的权限管理 sudo apt-get ins ...
- [转载]Ubuntu 安装 万能五笔 输入法
原文地址:Ubuntu 安装 万能五笔 输入法作者:庖丁解牛 paul@paul-desktop:~/scripts$ cat ins-ibus-wnwb.sh #!/bin/sh set -e cd ...
- GSL--GNU Scientific Library 小记
摘自http://qianjigui.iteye.com/blog/847612 GSL(GNU Scientific Library)是一个 C 写成的用于科学计算的库,下面是一些相关的包 Desi ...
- 转载:安装Ubuntu 15.10后要做的事
转载:安装Ubuntu 15.10后要做的事 原文转载于:http://blog.csdn.net/skykingf/article/details/45267517 Ubuntu 15.10发布了, ...
- ubuntu安装nginx时提示error: the HTTP rewrite module requires the PCRE library
ubuntu安装nginx时提示error: the HTTP rewrite module requires the PCRE library 须要安装pcre包. sudo apt-get upd ...
随机推荐
- Docker组件与元素(三)
说明: 这篇博文是根据国外的另一篇总结而来,第一个链接为原文,第二个为译文,第三个有几个图挺好 http://blog.flux7.com/blogs/docker ...
- Linux中安装python3.6和第三方库
Linux中安装python3.6和第三方库 如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,比如yum!!!!! ...
- XShell停止滚屏,禁止滚动
Ctrl+S:锁定当前屏幕 Ctrl+Q:解锁当前屏幕 Ctrl+Alt+] 进入命令输入状态
- solr6.4.1 搜索引擎(1)启动eclipse启动
solr是一个java写的搜索引擎,所以支持java方式的eclipse调试. 本篇文章使用solr版本为6.4.1 一. 环境 solr 下载地址 http://archive.apache.org ...
- Java异常学习总结二
异常的处理方式 方式一:捕获异常(try-catch-finally) 捕获异常是通过三个关键词来实现的:try-catch-finally.用try来执行一段程序,如果出现异常,系统抛出一个异常,可 ...
- MySQL架构之 主从+ProxySQL实现读写分离
准备服务器: docker run -d --privileged -v `pwd`/mysql_data:/data -p 3001:3306 --name mysql5-master --host ...
- delphi combobox屏蔽鼠标滑动
//第1种方法 procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; Mo ...
- fastjson中对象转化为字符串时过滤某字段
fastjson中对象转化为字符串时过滤某字段,有两种方法: 一.在该字符定义上方添加"@JSONField(serialize=false)"注解: 二.调用含有Property ...
- STL里的内存池实现
这个貌似有点复杂,解决的主要问题 就是 减少 内存分配次数,减少用户态核心态切换中断次数,提高运行速度,预分配 和线程池一个道理,预分配 ////////////////////自由链表 union ...
- mac下安装cnpm淘宝镜像
cnpm:官网 (事先已经安装了node,有npm)查看官网,提示安装需运行命令:npm install -g cnpm --registry=https://registry.npm.taobao. ...