在Windows x64和MinGW下使用GNU科学库(GSL) [英] Using GNU Scientific Library (GSL) under Windows x64 with MinGW

查看:648
本文介绍了在Windows x64和MinGW下使用GNU科学库(GSL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Microsoft Windows(64位)上的目录C:\MinGW(MSYS目录为C:\MinGW\msys\1.0)中安装了MinGW和MSYS.我已经从官方ftp 下载了最新的GNU科学库( GNU GSL )软件包.

I have installed MinGW and MSYS on Microsoft Windows (64bit), inside directory C:\MinGW (MSYS directory is C:\MinGW\msys\1.0). I have downloaded the latest GNU Scientific Library (GNU GSL) package from the official ftp.

我已经使用MSYS来成功执行configuremake,如GSL软件包中INSTALL文件中所述.这意味着,在MSYS命令行界面的MSYS home目录中,我已插入:

I have used MSYS to perform configure and make successfully as described in the INSTALL file in the GSL package. That means, in the MSYS command-line interface, in the MSYS home directory, I have inserted:

$ ./configure
$ make
$ make install

这将在MSYS目录(C:\MinGW\msys\1.0)下生成一个local目录,其中包括目录binincludelibshare.

This produces a local directory under the MSYS directory (C:\MinGW\msys\1.0) including the directories bin, include, lib, and share.

我已经成功编译了示例程序(根据$ a = 5 $计算Bessel函数$ J_0(x)$的值),根据GSL手册

I have successfully compiled the example program (which computes the value of the Bessel function $J_0 (x)$ at $x = 5$) according to the instructions in the GSL manual, by

$ gcc -Wall -I/usr/local/include -c example.c

这将按预期生成目标文件example.o,而没有任何错误消息.

This results in an object file example.o, as expected, without any error messages.

根据这将生成一个可执行文件a.exe,该可执行文件可以在MSYS环境中执行. 但是,在Windows命令行界面cmd.exe中,尝试运行可执行文件会出现以下错误消息:

This produces an executable a.exe which can be executed in the MSYS environment. However, in a Windows command-line interface, cmd.exe, trying to run the executable gives the following error message:

该程序无法启动,因为您的计算机缺少libgsl-0.dll.尝试重新安装该程序以解决此问题.

The program can't start because libgsl-0.dll is missing from your computer. Try reinstalling the program to fix this problem.

我想知道丢失了什么?应该怎么做才能生成可执行文件?

I wonder what is missing? What should one do to produce the executable file?

推荐答案

为MinGW构建项目时,在MSYS下,应始终./configure指定一个--prefix参数; (默认的/usr/local指定了MSYS特定的路径,这完全不适合MinGW应用程序开发).在您的情况下,您应该这样配置GSL:

When you build projects for MinGW, under MSYS, you should always specify a --prefix argument to ./configure; (the /usr/local default specifies an MSYS specific path, which is entirely unsuitable for MinGW application development). In your case, you should have configured GSL thus:

./configure --prefix=C:/MinGW

或者更好的是,将构建文件与源文件分开(例如,作为GSL顶级源目录的子目录):

or, better still, segregate the build files from the sources, (e.g. as a subdirectory of the GSL top source directory):

mkdir build
cd build
../configure --prefix=C:/MinGW

这可以确保程序包安装的所有库和头文件都位于适当的目录中,MinGW可以在其中找到它们,更重要的是,在MSYS之外运行时,通过%PATH%搜索找到已安装的DLL的地方.

This ensures that all libraries and headers installed by the package are located in appropriate directories, where MinGW can find them, and more importantly, where installed DLLs are found by a %PATH% search, when running outside of MSYS.

通过配置,随后再运行

make
make install

您已经安装了MinGW库和标头以供MSYS使用(这是错误的),尤其是libgsl-0.dll将已经安装到C:/MinGW/msys/1.0/local/bin中,而应该应该位于C:/MinGW/bin(这是后一个命令 的安装位置,并按照相应的--prefix=C:/MinGW规范进行配置).

you've installed MinGW libraries and headers for use by MSYS, (which is wrong), and in particular libgsl-0.dll will have been installed into C:/MinGW/msys/1.0/local/bin, whereas it should be in C:/MinGW/bin, (which is where the latter command would have installed it, following configuration with the appropriate --prefix=C:/MinGW specification).

重要脚注

您应注意,上述过程将正确准备GSL(或以类似方式准备的任何其他库)以与MinGW配合使用,并允许您运行与开发主机上与此类库链接的应用程序,(或在安装了类似MinGW的任何其他主机上).但是,如果您希望分发此类应用程序(并遵守任何许可条件),以便它们可以作为独立的应用程序运行(即,无需在最终用户的计算机上安装MinGW),则您必须注意,您的发行版中的运行时相关性将得到适当满足.为此,您必须选择以下任一选项:

You should note that the preceding procedure will correctly prepare GSL, (or any other library prepared in similar fashion), for use with MinGW, and will allow you to run applications which you've linked with such libraries on your development host, (or on any other host with a similar MinGW installation). However, if you wish to distribute such applications, (and provided you comply with any licensing conditions), so that they may be run as free-standing applications, (i.e. without a requirement that MinGW be installed on the end user's machine), you must take care that run time dependencies will be properly satisfied in your distribution. To achieve this, you must choose either to:

  1. 静态地链接应用程序.如果您的发行版仅限于一个或两个可执行文件,则这可能是适当的,但随着可分发应用程序套件中具有公共核心库依赖关系的可执行文件数量增加,将迅速导致可执行文件膨胀".在后一种情况下,更好的选择是
  2. 动态链接应用程序,并分发所有必需的DLL(系统DLL除外)以及应用程序套件的副本;在这种情况下,您不应假设目录布局或%PATH%设置可能会或可能不会应用于最终用户的计算机上;您应该简单地打包您的发行版,以便将所有交付的可执行文件及其随附的DLL安装到一个相同的目录中.
  1. Link the application statically. This may be appropriate, if your distribution is limited to one, or maybe two executables, but will quickly lead to "executable bloat" as the number of executables with a common core library dependency increases, within a distributable application suite. In the latter case, a better choice would be to
  2. Link the application dynamically, and distribute copies of any necessary DLLs, (other than system DLLs), along with the application suite; in this case, you should make no assumptions regarding directory layout or %PATH% settings which may or may not apply on the end user's machine; you should simply package your distribution such that all delivered executables and their accompanying DLLs will be installed into one and the same directory.

这篇关于在Windows x64和MinGW下使用GNU科学库(GSL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆