将fortran程序从ubuntu移植到windows的问题 [英] Problems with porting a fortran program from ubuntu to windows

查看:494
本文介绍了将fortran程序从ubuntu移植到windows的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前有一些麻烦更新旧的代码,仍然需要一个不支持的编译器和昂贵的库到一个版本的gfortran在Windows上的Eclipse。我让它休息一段时间,最近我采取了一个其他的方法,从头开始重新构建程序,在ubuntu机器上开发,但现在我想把它带回到Windows机器,以便我的同事可以贡献。



状态:




  • 计划编译,运行并在ubuntu计算机与GCC GNU编译器

  • Windows 7计算机64位

  • 使用lapack和liblapack-devel的Cygwin安装(对于gnu fortran)我不使用这些,因为我手动编译blas和lapack)

  • (C:/ cygwin / lib添加到Windows路径)



原始问题:



程序在cygwin中编译(通过调用 make - 命令,使用位于此处的makefile调用make命令: http:/ /thijsvandenbrande.be/phd/hamfemInstall/makefile



这会返回hamfem.exe文件,该文件在双击时会返回以下错误Windows:程序无法启动,因为cyglap​​ack-0.dll从您的计算机中丢失。请尝试重新安装程序来解决这个问题。



当从cygwin运行可执行文件时,通过调用 ./ hamfem.exe 命令,可执行文件开始运行。但是,我想要一个解决方案,以便我可以给这个可执行文件给我的同事,以便他们可以更改输入文件(位于一个文件夹中有一个相对路径的可执行文件)。



继续阅读下面的评论,我尝试了下面的事情:


  1. 在Windows路径中添加 C:\cygwin\lib\lapack\cyglap​​ack-0.dll 文件的确切路径,甚至在以后重新启动也无济于事。

  2. 在调用库之前向makefile添加-static,导致依赖性错误,因为我使用lapack库的两个命令依赖于很多其他命令(DPBTRF和DPBTRS) 。这些命令在mainprog.f90模块中使用。错误: /usr/lib/gcc/i686-pc-cygwin/4.7.3 /../../../ liblapack.a(dpbtrf.fo):在函数'dpbtrf':
    /usr/src/debug/lapack-3.4.2-1/SRC/dpbtrf.f:277:未定义对dtrsm_
    的引用,以及几行

  3. liblapack.a 文件添加到src文件夹,但编译器总是回到cygwin

在lapack的网站上,您通常可以下载函数及其依赖关系(例如 DPBTRF ),但这些不再可用。有没有人有另一个想法如何包括这两个函数及其依赖关系在静态库文件,我可以预先编译并添加到 src -folder?



当前(半)修复



接下来的事情对我有用按照 http://gcc.gnu.org/wiki/GfortranBuild 上的说明手动构建libblas .a和liblapack.a放在Cygwin的 / usr / src 文件夹中,并在makefile中引用这个文件夹。更新的makefile可以在这里找到: http://thijsvandenbrande.be/phd/hamfemInstall/makefileNew



该代码通过从cygwin运行make命令(在进程的下一步,从Eclipse运行)在Windows上编译得很好,我得到一个.exe文件,可以通过双击运行,如果我把它的文件夹移动到另一个位置,它会继续运行。因为这个过程是相当劳动密集型的,把所有的东西,我添加了下面的答案,说明你必须解析到cygwin的命令,以使其工作。



您的信息:我的文件结构看起来像这样(在构建之后,我将.exe文件移动一个文件夹,在linux版本作为Windows版本) li> input.txt

  • NGCR_building01.txt



  • (例程输出文件的空文件夹)


  • src

    • hamfem.f90(主文件)

    • mainprog.f90(包含来自lapack的命令的文件)

    • ...一组其他模块)

    • makefile



  • 解决方案

    我想出了自己的事情,有一些指针从stackoverflow。为了让其他人帮助他们解决类似的问题,我想在这里的工作方法,以便完全记录这个问题。



    这个问题可以通过干净的构建Lapack库!和Blas库在你的本地机器上在cygwin和粘贴liblapack.a和libblas.a文件到你在makefile中引用的库文件夹。通过静态调用Lapack而抛出的错误,其中Blas的一些例程的结果在两个命令中使用。



    这些是我遵循的步骤:


    1. 下载lapack.tgz blas.tgz文件,并将其添加到 C:\Cygwin\usr\src 文件夹中

    2. 使用cygwin中的以下命令提取这些文件:

        cd / usr / src 
      tar -xvzf lapack.tgz
      tar -xvzf blas.tgz


    3. 使用命令构建两个库文件如下图所示在Cygwin中。编译Lapack可能需要一段时间,并且最终会导致一些错误,因为测试文件中有一些缺少的链接。这些测试运行精度工具。需要更详细地查看 make.inc 文件来解决这些问题。

        cd $ HOME 
      cd / usr / src / BLAS
      make
      mv blas_LINUX.a ../libblas.a
      cd ../lapack-3.4.2
      mv make.inc.example make.inc
      make
      mv liblapack.a ../liblapack.a


    4. 检查此存储库中包含的makefile是否正确链接到库。这些应该说 / usr / src -static -llapack -lblas ,其他选项是为linux编译器。



    I previously had some troubles updating old code that still needed a not supported compiler and expensive libraries to a version with gfortran in Eclipse on Windows. I let it rest for a while and recently I took a whole other approach, rebuilding the program from scratch, developping on a ubuntu machine, but now I want to bring it back to a windows machine so that my co-workers can contribute on it.

    The status:

    • Program compiles, runs and gives good results on an ubuntu machine with the GCC GNU compiler
    • Windows 7 machine, 64bit
    • Cygwin installation (for gnu fortran) with lapack and liblapack-devel (however, I don't use these, because I compile blas and lapack manually)
    • (C:/cygwin/lib added to windows Path)

    Original Issue:

    The program compiles in cygwin (by calling the make-command, calling the make command with the makefile situated here: http://thijsvandenbrande.be/phd/hamfemInstall/makefile

    This returns the file hamfem.exe which returns the following error when runned by double-clicking on it in windows: The program can't start because cyglapack-0.dll is missing from your computer. Try reinstalling the program to fix this problem.

    When running the executable from cygwin, by calling the ./hamfem.exe command the executable starts to run. However, I want a solution so that I can give this executable to my co-workers so that they can change the input files (located in a folder in that has a relative path to the executable).

    Going further on the comments below, I tried the next things:

    1. Adding the exact path to the C:\cygwin\lib\lapack\cyglapack-0.dll file in windows path and even rebooting afterwards doesn't help.
    2. adding a -static to the makefile before calling the library, resulting in dependency errors because I use two commands of the lapack library that depend on quite a lot of other commands (DPBTRF and DPBTRS). These commands are used in the mainprog.f90 module. The error: /usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../liblapack.a(dpbtrf.f.o): In function 'dpbtrf': /usr/src/debug/lapack-3.4.2-1/SRC/dpbtrf.f:277: undefined reference to 'dtrsm_' and a couple of more lines stating the dependencies.
    3. add the liblapack.a file to the src folder, but compiler always goes back to the lapack in cygwin

    On the website of lapack you can normally download the functions with their dependencies (example DPBTRF), but these are not available anymore. Does anyone have another idea how to include these two functions and their dependencies in a static library-file that I can compile beforehand and add to the src-folder?

    Current (semi-)Fix

    The next thing worked (a bit) for me: following the instructions on http://gcc.gnu.org/wiki/GfortranBuild to manually build libblas.a and liblapack.a in the /usr/src folder of Cygwin and refering to this folder in the makefile. The updated makefile can be found here: http://thijsvandenbrande.be/phd/hamfemInstall/makefileNew

    The code compiles nicely on Windows by running the make command from cygwin (next step in the process, running it out of Eclipse) and i get a .exe file that can be run by double clicking it and that keeps running if I move it with its folder to another location. Because this process is quite labour intensive, figuring it all out, I added the answer here below, stating the commands you have to parse to cygwin in order to make it work.

    For your information: my file structure looks like this (after the build, I move the .exe file one folder up, both in the linux version as the windows version):

    • hamfem.exe
    • in
      • input.txt
      • NGCR_building01.txt
    • out
      • (empty folder for output files of the routine)
    • src
      • hamfem.f90 (main file)
      • mainprog.f90 (file that contains the commands from lapack)
      • ...(a bunch of other modules)
      • makefile

    解决方案

    I figured things out myself, with some pointers from all over stackoverflow. In order for others to help them resolve similar issues, I would like my work method here so that the question is fully documented.

    The issue can be resolved by clean building the Lapack library !and the Blas library on your local machine in cygwin and pasting the liblapack.a and libblas.a file to the library folder that you refer to in the makefile. The errors that were casted by calling Lapack staticly where a result of some routines of Blas used in the two commands.

    These are the steps I followed:

    1. download the lapack.tgz and blas.tgz files from the website and past them in the C:\Cygwin\usr\src folder
    2. Extract these files with the following commands in cygwin:

      cd /usr/src 
      tar -xvzf lapack.tgz
      tar -xvzf blas.tgz
      

    3. Build the two library files with the commands shown below in Cygwin. Compiling Lapack can take a while and will result in some errors in the end because of some missing links in the test files. These tests are run for accuracy tools. A more detailed look into the make.inc file is needed to resolve these issues.

      cd $HOME 
      cd /usr/src/BLAS
      make
      mv blas_LINUX.a ../libblas.a
      cd ../lapack-3.4.2
      mv make.inc.example make.inc
      make
      mv liblapack.a ../liblapack.a
      

    4. check the makefile included in this repository for the correct linking to the libraries. These should say /usr/src and -static -llapack -lblas, the other options are for the linux compiler.

    这篇关于将fortran程序从ubuntu移植到windows的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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