简体   繁体   English

如何设置 linux 将 FORTRAN 代码编译成 windows 二进制文件?

[英]How can I setup linux to compile FORTRAN code into windows binaries?

I'm working on a FORTRAN project and I would like to build all of the binaries that I want to maintain on a linux machine that is dedicated for automated builds.我正在开发一个 FORTRAN 项目,我想在专用于自动构建的 linux 机器上构建我想要维护的所有二进制文件。 I have successfully used mingw to build 32-bit and 64-bit binaries from C source for windows machines on the linux machine with the following packages on Ubuntu. I have successfully used mingw to build 32-bit and 64-bit binaries from C source for windows machines on the linux machine with the following packages on Ubuntu.

apt-get install mingw32
apt-get install mingw-w64

Then I run the following commands to actually compile:然后我运行以下命令来实际编译:

gcc -b amd64-mingw32msvc -V 4.4.4 -o <...other options>

However, the mingw packages that I've obtained via apt-get do not include FORTRAN compilers.但是,我通过 apt-get 获得的mingw包不包括 FORTRAN 编译器。

Anybody got any ideas on what I can do?有人对我能做什么有任何想法吗?

I know this is an old thread but a few things seem to have changed and people might still be interested in the topic.我知道这是一个旧线程,但有些事情似乎已经改变,人们可能仍然对该主题感兴趣。

Problem: I want to use my linux machine to compile some code and create a.exe that I can send to people using Windows.问题:我想用我的 linux 机器编译一些代码并创建一个我可以发送给使用 Windows 的人的.exe。

Solution: Essentially here: http://mxe.cc/解决方案:基本上在这里:http://mxe.cc/

What I did:我做了什么:

  • Check to see if your system has all the software you need here在此处检查您的系统是否具有您需要的所有软件
  • run

git clone -b stable https://github.com/mxe/mxe.git

It will download a few small things and create the directory "mxe" (probably in your home folder)它将下载一些小东西并创建目录“mxe”(可能在您的主文件夹中)

  • cd into that mxe directory and run "make". cd 进入那个 mxe 目录并运行“make”。 HOWEVER: this would take hours and take up a few GB on your hard drive so instead run something like但是:这将花费数小时并在您的硬盘驱动器上占用几 GB,因此请运行类似

    make mpfr eigen opencsg cgal qt

For more ideas on how to shorten that all see this or the mxe tutorial or somewhere else;)有关如何缩短所有内容的更多想法,请参阅或 mxe 教程或其他地方;)

  • The easiest way to compile stuff then seems to be something like:编译东西的最简单方法似乎是:

    ~/mxe/usr/bin/i686-pc-mingw32-gfortran -c main.f95

    ~/mxe/usr/bin/i686-pc-mingw32-gfortran main.o -o outfile.exe

Of course you can chose something other than fortran, just consult the mxe/usr/bin to see what its called.当然你也可以选择 fortran 以外的东西,只要参考 mxe/usr/bin 看看它叫什么。

if you got mingw32 and the Gnu C cross compiler is working for you... when why not just get the Gnu Fortran cross compiler, too?如果你有 mingw32 和 Gnu C 交叉编译器正在为你工作......为什么不直接获得 Gnu Fortran 交叉编译器呢?

http://www.nber.org/sys-admin/mingw32-fortran-fedora.html http://www.nber.org/sys-admin/mingw32-fortran-fedora.html

EXAMPLE apt-get install mingw32-gcc-fortran

You can always download and install a prebuilt compiler from the MinGW(-w64) project itself:您始终可以从 MinGW(-w64) 项目本身下载并安装预构建的编译器:

Windows 64-bit: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/4.6.2-1/ Windows 32-bit: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/4.6.2-1/ Windows 64-bit: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/4.6.2-1/ Windows 32-bit: http://sourceforge. net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/4.6.2-1/

Just unpack somewhere and add the cross*/bin directory to PATH.只需在某处解压缩并将cross*/bin目录添加到 PATH。

I include (obj)c(++) and fortran.我包括 (obj)c(++) 和 fortran。

On Ubuntu 18.04 I use在 Ubuntu 18.04 我使用

apt install gfortran-mingw-w64

Then use the compiler x86_64-w64-mingw32-gfortran in place of gfortran .然后使用编译器x86_64-w64-mingw32-gfortran代替gfortran If you're using cmake, you can configure the compiler from the build directory like so:如果您使用 cmake,您可以从构建目录配置编译器,如下所示:

FC=x86_64-w64-mingw32-gfortran cmake ..

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

相关问题 如何从Windows反编译Linux二进制文件? - How can I decompile Linux binaries from Windows? 是否可以在Linux机器上编译Windows二进制文件? - Is it possible to compile Windows binaries on a Linux machine? 一个人可以在Linux上编译Windows代码吗? - Can one compile Windows code on Linux? 如何在Windows上编译Linux内核代码? - How to compile Linux kernel code on Windows? MPI fortran 代码用 cygwin 在 linux 和 windows 中编译 - MPI fortran code compiled in linux and windows with cygwin 如何在Windows 7 32位上编译/执行以下代码? - How can I compile / execute the following code on Windows 7 32 Bit? 据我所知,你无法在Windows上编译Swift,那么SwiftStub如何在Windows上编译代码呢? - As far as I know, you can't compile Swift on Windows, so how does SwiftStub compile code on Windows? 如何在Windows 10下自动设置和配置Linux的Windows子系统? - How can I automatically setup and configure the Windows Subsystem for Linux under Windows 10? 如何在Windows上交叉编译C代码,以便在Unix(Solaris / HPUX / Linux)上运行二进制文件? - How do I cross-compile C code on Windows for a binary to also be run on Unix (Solaris/HPUX/Linux)? 如果我在Linux OS上运行,如何使用gcc g ++编译Windows二进制文件? - How can I use gcc g++ to compile a windows binary if I am running on a Linux OS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM