简体   繁体   English

在Cygwin上的MinGW。 链接GNU科学库的一些问题

[英]MinGW on Cygwin. Some issues on linking the GNU Scientific Library

I have a couple of issues when linking the GNU Scientific Library with MinGW on Cygwin. 将GNU科学图书馆与Cygwin上的MinGW链接时,我遇到几个问题。 Let me explain the situation. 让我解释一下情况。

I have installed both MinGW and GSL from the Cygwin setup utility. 我已经从Cygwin设置实用程序中安装了MinGW和GSL。 The path /usr/i686-w64-mingw32/sys-root/mingw/bin/ contains: 路径/usr/i686-w64-mingw32/sys-root/mingw/bin/包含:

gsl-config           libgfortran-3.dll                 libssp-0.dll
libatomic-1.dll      libgomp-1.dll                     libstdc++-6.dll
libblas.dll          libgomp-plugin-host_nonshm-1.dll  libvtv_stubs-0.dll
libcblas.dll         libgsl-19.dll                     libvtv-0.dll
libgcc_s_sjlj-1.dll  libquadmath-0.dll                 libwinpthread-1.dll

The path /usr/i686-w64-mingw32/sys-root/mingw/include/ contains all the GSL headers. 路径/usr/i686-w64-mingw32/sys-root/mingw/include/包含所有GSL标头。

The path /usr/i686-w64-mingw32/sys-root/mingw/lib/ contains, among many other libraries, the files libgsl.dll.a and libgslcblas.dll.a 路径/usr/i686-w64-mingw32/sys-root/mingw/lib/包含文件libgsl.dll.alibgslcblas.dll.a等文件

If I compile using 如果我使用编译

i686-w64-mingw32-g++.exe -std=c++11 -s someGSLapp.cpp -lgsl -static-libgcc -Wl,-Bstatic -lstdc++ -lpthread -lm

it compiles without any problem, and the executable can be run provided /usr/i686-w64-mingw32/sys-root/mingw/bin/ is properly added to PATH environment variable. 它可以编译而没有任何问题,并且只要/usr/i686-w64-mingw32/sys-root/mingw/bin/已正确添加到PATH环境变量中,便可以运行该可执行文件。

Let me point out the first strange issue. 让我指出第一个奇怪的问题。 If I do not set the PATH variable, in order to run my program, I have to copy all files in /usr/i686-w64-mingw32/sys-root/mingw/bin/ into the path where my executable is located. 如果未设置PATH变量,则为了运行程序,必须将/usr/i686-w64-mingw32/sys-root/mingw/bin/所有文件复制到可执行文件所在的路径中。 Be careful, ALL files, not only the GSL DLLs. 请注意,所有文件,不仅是GSL DLL,都是这样。 This is strange, because other libraries are linked statically. 这很奇怪,因为其他库是静态链接的。 Indeed, I have other programs that do not use GSL, and when I compile them statically linking the standard library in the same way as I do for my someGSLapp above, they can be run without setting PATH, nor copying any DLLs. 确实,我有其他不使用GSL的程序,当我以与上述someGSLapp相同的方式将它们静态链接到标准库时,可以在不设置PATH的情况下运行它们,也无需复制任何DLL。

The second issue happens when I try to statically link the GSL. 当我尝试静态链接GSL时,会发生第二个问题。 If I try: 如果我尝试:

i686-w64-mingw32-g++.exe -std=c++11 -s someGSLapp.cpp -static-libgcc -Wl,-Bstatic -lstdc++ -lpthread -lm -lgsl

the GNU linker returns the error cannot find -lgsl . GNU链接器返回错误cannot find -lgsl I tried to add 我试图添加

-I/usr/i686-w64-mingw32/sys-root/mingw/include/
-L/usr/i686-w64-mingw32/sys-root/mingw/lib/

but it does not change anything, I still get the same error. 但它并没有改变任何东西,我仍然遇到相同的错误。

So, concerning the first issue, could anyone explain why I need to copy ALL the DLLs? 那么,关于第一个问题,谁能解释为什么我需要复制所有DLL? My tentative explanation is that the GSL DLL needs the others, but I cannot understand why even the fortran DLL is needed. 我的初步解释是GSL DLL需要其他,但我不明白为什么甚至需要fortran DLL。

Concerning the second issue, could anyone tell me how to link the GSL statically? 关于第二个问题,谁能告诉我如何静态链接GSL?

UPDATE on the second issue 关于第二期的更新

If I link statically using 如果我使用静态链接

i686-w64-mingw32-g++.exe -std=c++11 -s someGSLapp.cpp -static-libgcc -Wl,-Bstatic -lstdc++ -lpthread -lm -lgsl.dll

I do not get the error cannot find -lgsl anymore, compilation and linking terminate without any error or warning, but the executable still do not run if I do not set PATH or copy all the DLLs as seen above. 我没有得到该错误, cannot find -lgsl了,编译和链接终止而没有任何错误或警告,但是如果我未设置PATH或复制所有DLL,则可执行文件仍然无法运行,如上所述。 It seems that static linking is not working for the GSL. 似乎静态链接不适用于GSL。

Try adding -static. 尝试添加-static。 Linking a DLL might not generate a static dependency on the library without the according flag, if at all. 如果没有,则链接DLL可能不会在没有相应标志的情况下对库产生静态依赖关系。 Also linking stdc++ is usually not needed. 通常也不需要链接stdc ++。 (as is the -W,.. If -static is used. (和-W一样。.如果使用-static。

I solved the problem. 我解决了问题。 It seems that precompiled GSL packages currently available through the Cygwin setup utility does not allow to statically link the library. 似乎当前可以通过Cygwin设置实用程序使用的预编译GSL软件包不允许静态链接库。 Indeed, as noticed by @ssbssa in a comment, they do not install libgsl.a 实际上,正如@ssbssa在评论中注意到的那样,他们没有安装libgsl.a。

This is what I did. 这就是我所做的。 First I completely removed all GSL packages previously installed. 首先,我完全删除了先前安装的所有GSL软件包。 From the main GSL repository ftp://ftp.gnu.org/gnu/gsl/ I downloaded the latest version of the library into a local path. 我从GSL主存储库ftp://ftp.gnu.org/gnu/gsl/下载了该库的最新版本到本地路径。

GNU make has to be already installed. GNU make必须已经安装。 I used 我用了

./configure CC=x86_64-w64-mingw32-gcc --prefix=/usr/gsl/mingw64/

CC sets the compiler to be used. CC设置要使用的编译器。 --prefix sets the path the library will be installed into. --prefix设置库将安装到的路径。 Then I called make and, as soon it finished compiling, make install . 然后我打电话给make并在完成编译后立即make install

Since I need to compile programs also for 32 bit systems, I called make clean to start a new installation, then I set 由于我还需要为32位系统编译程序,因此我调用make clean开始新安装,然后设置

./configure CC=i686-w64-mingw32-gcc --prefix=/usr/gsl/mingw32/

and then again make and make install . 然后再次makemake install Now I can cross-compile programs using GSL for both 32 and 64 bits, and I can statically link the library simply adding the -static flag 现在,我可以使用32位和64位GSL交叉编译程序,并且只需添加-static标志即可静态链接库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM