在WINDOWS中安装使用GSL(MinGW64+Sublime Text3 & Visual Studio)

您所在的位置:网站首页 CrushOnYou是什么意思 在WINDOWS中安装使用GSL(MinGW64+Sublime Text3 & Visual Studio)

在WINDOWS中安装使用GSL(MinGW64+Sublime Text3 & Visual Studio)

2023-11-12 06:00| 来源: 网络整理| 查看: 265

        本文介绍在Windows下安装使用GSL库,涉及GSL两个版本(官方最新版及GSL1.8 VC版)、msys shell、GCC、G++等内容,最终实现对GSL安装及示例基于MinGW64在Sublime Text3下的编译运行,并实现GSL在Visual Studio下的使用及部分示例测试。还介绍了GSL1.8 VC版本的编译使用过程。

目录

一、GSL简介

二、在WINDOWS下安装介绍

三、安装使用GSL (GNU)

1. 安装过程(32bit & 64bit)

2. 使用过程(基于MinGW-w64命令行及Sublime Text3和Visual Studio)

四、安装使用Gsl1.8(GnuWin32)

总结

 

一、GSL简介

(官方介绍,不做累述)

GSL简介及下载地址:GSL - GNU Scientific Library

l  Introduction

The GNU Scientific Library (GSL) is a numerical library for C and C++ programmers. It is free software under the GNU General Public License.

The library provides a wide range of mathematical routines such as random number generators, special functions and least-squares fitting. There are over 1000 functions in total with an extensive test suite.

The complete range of subject areas covered by the library includes,

Complex Numbers

Roots of Polynomials

Special Functions

Vectors and Matrices

Permutations

Sorting

BLAS Support

Linear Algebra

Eigensystems

Fast Fourier Transforms

Quadrature

Random Numbers

Quasi-Random Sequences

Random Distributions

Statistics

Histograms

N-Tuples

Monte Carlo Integration

Simulated Annealing

Differential Equations

Interpolation

Numerical Differentiation

Chebyshev Approximation

Series Acceleration

Discrete Hankel Transforms

Root-Finding

Minimization

Least-Squares Fitting

Physical Constants

IEEE Floating-Point

Discrete Wavelet Transforms

Basis splines

Running Statistics

Sparse Matrices and Linear Algebra

Unlike the licenses of proprietary numerical libraries the license of GSL does not restrict scientific cooperation. It allows you to share your programs freely with others.

l  Downloading GSL

The current stable version is GSL-2.4. It was released on 19 June 2017. Details of recent changes can be found in the NEWS file.

GSL can be found in the gsl subdirectory on your nearest GNU mirror http://ftpmirror.gnu.org/gsl/.

Main GNU ftp site: ftp://ftp.gnu.org/gnu/gsl/

For other ways to obtain GSL, please read How to get GNU Software

Installation instructions can be found in the included README and INSTALL files.

Precompiled binary packages are included in most GNU/Linux distributions.

A compiled version of GSL is available as part of Cygwin on Windows.

l  Documentation

GSL includes a reference manual in reStructuredText format. You can view the manual in HTML and PDF, or read it on your system using the shell command info gsl-ref (if the library is installed).

The GSL Reference Manual is available online,

GSL Reference Manual - HTML GSL Reference Manual - PDF

 

二、在WINDOWS下安装介绍

        GSL在Windows下,可通过安装Cygwin使用,因其自带GSL库;本文主要介绍在MinGW下用msys生成GSL最新版的静态库、导入库及动态库过程,并通过命令行、Sublime Text3或Visual Studio编译使用GSL库;另外介绍了GSL1.8 VC版在Visual Studio2015下的编译使用。

三、安装使用GSL (GNU)

官方建议的最简单编译安装方式:

  1. `cd' to the directory containing the package's source code and type  `./configure' to configure the package for your system. Running `configure' might take a while.  While running, it prints  some messages telling which features it is checking for.

  2. Type `make' to compile the package.

  3. Type `make install' to install the programs and any data files and documentation.  When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular  user, and only the `make install' phase executed with root privileges. OR  For example, `make install prefix=/alternate/directory'。

GSL最新版源码解压后目录内容如下:

 

1.  安装过程(32bit & 64bit)

        要执行上面的三个步骤,首先需要一个UNIX环境,在Windows下,可以使用msys来模拟,MSYS是一个小型的GNU环境,是一个通过将Linux源代码在Win32上编译而成的UNIX工作环境;MSYS类似于Cygwin,但是由于工作原理的不同,速度更快、体积更小、功能强大、便于携带;使用MSYS可以取代商业的VC环境,同样开发出商业版权的程序而不受任何版权限制;可从MinGW32官方下载,在此推荐一个集成版下载,其集成了多个实用工具,本文采用集成版msys。将下载的msys集成版压缩包解压后,将msys文件夹直接复制到自己喜欢的地方,建议放在MinGW目录下,便于明确归属。然后将/bin目录加到系统PATH中。

 

另外,还需要准备MinGW编译工具,在此就MinGW做一下简单介绍,MinGW 的全称是:Minimalist GNU on Windows 。它提供了一套简单方便的Windows下的基于GCC 程序开发环境,是从Cygwin里fork出来的。当初只考虑32位,和Cygwin相比,不强调POSIX兼容性而相对强调性能和减小依赖。目前还存在的版本有MinGW-w64, MinGW-w64 与 MinGW 的区别在于 MinGW 只能编译生成32位可执行程序,而 MinGW-w64 则可以编译生成 64位 或 32位 可执行程序。(据说,MinGW-W64的主要维护者Kai Tietz因为工作需要,他想让MinGW提供扩充x64支持,但对方态度很不友好,于是愤而fork出来,这就是MinGW-W64的由来:)。现在推荐使用MinGW-w64,因GSL的按照会根据本地系统平台自动生成,也就是说在64位系统下会自动匹配64位的GCC,这样生成的库文件无法在x86的项目中编译通过,因此,需要在本地下载配置32位和64位的MinGW-w64。

先进入MinGW-w64下载地址:https://sourceforge.net/projects/mingw-w64/files/,在此页面根据平台需要链接64位或32位,本示例使用的版本是:x86_64-7.1.0-release-posix-seh-rt_v5-rev2.7z和i686-7.1.0-release-posix-dwarf-rt_v5-rev2.7z,解压后,将bin目录添加到系统路径中(系统路径中应仅存在一个版本的bin目录),在命令行提示符下输入"gcc -v"或"g++ -v"来查看版本信息。

对应关系:

32bit g++.exe —> i686-w64-mingw32-g++

32bit gcc.exe —> i686-w64-mingw32-gcc

64bit g++.exe —> x86_64-w64-mingw32-g++

64bit gcc.exe —> x86_64-w64-mingw32-gcc

根据拟编译GSL的平台环境,配置好MinGW-w64后,进入msys目录,在此目录中执行msys.bat(直接双击运行或以超级管理员身份运行),在$提示符下输入help的界面如下图:

 

在$提示符下输入:

   cd空格/盘符/gsl源码目录/——如:cd /c/gnu/gslmsys_code

进入该目录后,进行GSL安装的三个步骤,先后执行:

1)     ./configure    ——  此过程较慢,耐心等待即可(针对32位编译,执行CFLAGS="-m32" CXXFLAGS="-m32" ./configure)

2)     make  ——  编译生成过程

3)     make install  ——  将编译好的库和头文件等安装在\local目录中。

 

安装后的GSL目录中含有bin、lib、include、share四个文件夹

 

至此,GSL最新版安装完成,GSL库目录结构如下:

\bin (libgsl-23.dll、libgslcblas-0.dll)

\include  (\gsl\gsl_*.h)

\lib  (libgsl.a、libgsl.la、libgsl.dll.a、libgslcblas.a、libgslcblas.la、libgslcblas.dll.a)

\share

2.  使用过程(基于MinGW-w64命令行及Sublime Text3和Visual Studio) 示例代码

在自己的示例代码目录下新建一个C或CPP文件,复制示例代码并保存。

C示例代码:(gsldemo.c)

#include #include int main () { double x = 5.0; double y = gsl_sf_bessel_J0 (x); printf ("J0(%g) = %.18e\n", x, y); return 0; // Expected output: J0(5) = -1.775967713143382600e-001 }

CPP示例代码:(gsldemo.cpp)

//#include #include #include //for use std::setprecision() #include using namespace std; int main () { double x = 5.0; double y = gsl_sf_bessel_J0 (x); //printf ("J0(%g) = %.18e\n", x, y); cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3