简体   繁体   English

使用Windows编译Linux的Ada程序

[英]Compile Ada program for Linux using Windows

If I want to compile a program that is written in Ada, I have to use GNAT, of course. 如果我想编译一个用Ada编写的程序,我当然必须使用GNAT。

As my Computer has Windows as its sole operating system, I cannot use GNAT, normally. 由于我的计算机将Windows作为其唯一的操作系统,我通常不能使用GNAT。 Right? 对? Thus I got Cygwin which enables me to use GNAT on Windows. 因此我得到了Cygwin,这使我能够在Windows上使用GNAT。

But the result is an executable that runs under Windows - not Linux. 但结果是在Windows下运行的可执行文件 - 而不是Linux。 So how can I compile the Ada code for Linux although I only have Windows? 那么我怎么能编译Linux的Ada代码,虽然我只有Windows? (Please don't think about the reasons ...) (请不要考虑原因......)

Is this possible with Cygwin? 这可能与Cygwin有关吗? Do I have to install a virtual machine with Linux? 我是否必须使用Linux安装虚拟机? Or is there another (easier) solution to this issue? 或者是否有另一个(更简单的)解决方案?

I have to use GNAT, of course. 当然,我必须使用GNAT。

Not true; 不对; there are other Ada compilers. 还有其他Ada编译器。 (GNAT is the only one I know of that's free.) (GNAT是我所知道的唯一免费的。)

Running GNAT under Cygwin gives you Cygwin executables, which are Windows executables that depend on cygwin1.dll . 在Cygwin下运行GNAT会为您提供Cygwin可执行文件,这些可执行文件是依赖于cygwin1.dll Windows可执行文件。 They will not work on Linux. 它们不适用于Linux。 See the "What ... isn't it?" 请参阅“什么......不是吗?” section on the Cygwin home page . Cygwin主页上的部分

There is a GNAT for Windows. 有一个GNAT for Windows。 The GNAT Pro version has a list of supported platforms here ; 蚋专业版还支持平台的列表在这里 ; it includes Linux and Windows, but it doesn't show a Windows-to-Linux cross compiler. 它包括Linux和Windows,但它没有显示Windows到Linux的交叉编译器。

Since GNAT is free software (GNAT Pro isn't is a little more complicated; I won't get into that) there could well be a Windows-to-Linux GNAT cross-compiler -- or, if you're really ambitious, you could build one yourself (or hire someone to do it for you). 由于GNAT是免费软件(GNAT Pro 不是 那么复杂;我不会涉及到这一点),很可能是Windows到Linux GNAT交叉编译器 - 或者,如果你真的雄心勃勃,你可以自己建造一个(或聘请某人为你做)。

But installing GNAT on a Linux system is the easiest approach. 但是在Linux系统上安装GNAT是最简单的方法。 It doesn't have to be a virtual machine. 这并不一定是一个虚拟机。 If you have the hardware, you can install some Linux system by itself, or you can set up a dual-boot system on your Windows box. 如果您有硬件,可以自行安装某些Linux系统,也可以在Windows机器上设置双启动系统。 Ubuntu has a Windows installer, Wubi , that installs an Ubuntu image as a Windows file; Ubuntu有一个Windows安装程序Wubi ,它将Ubuntu映像安装为Windows文件; it doesn't let you run Windows and Ubuntu concurrently, but it lets you dual-boot without having to repartition. 它不允许您同时运行Windows和Ubuntu,但它允许您双启动而无需重新分区。

There are other options; 还有其他选择; these are just the ones I'm familiar with. 这些只是我熟悉的。

Is this possible with Cygwin? 这可能与Cygwin有关吗?

It's probably possible . 这可能是可能的

Do I have to install a virtual machine with Linux? 我是否必须使用Linux安装虚拟机? Or is there another (easier) solution to this issue? 或者是否有另一个(更简单的)解决方案?

Installing a Linux on a virtual machine is likely to be the simplest solution to your problem. 在虚拟机上安装Linux可能是解决您问题的最简单方法。

Since GNAT is free software (GNAT Pro isn't; I won't get into that) there could well be a Windows-to-Linux GNAT cross-compiler -- or, if you're really ambitious, you could build one yourself (or hire someone to do it for you). 由于GNAT是免费软件(GNAT Pro不是;我不会参与其中),很可能是Windows到Linux GNAT交叉编译器 - 或者,如果你真的雄心勃勃,你可以自己构建一个(或聘请某人为你做这件事)。

Actually GNAT Pro is Free Software, free as in freedom, not as in beer. 实际上GNAT Pro是免费软件,在自由中是免费的,而不是在啤酒中。

And I think that it would be simplest to install Linux in virtual machine and compile with it. 我认为在虚拟机中安装Linux并使用它进行编译是最简单的。

AdaCore has a gnat compiler for the Windows operating system freely available at: http://libre.adacore.com/libre/download/ and choose "Free Software..." and click "Build Your Download Package" and go from there. AdaCore有一个用于Windows操作系统的gnat编译器,可从以下网址免费获得: http//libre.adacore.com/libre/download/并选择“Free Software ...”并单击“Build Your Download Package”并从那里开始。 As Keith Thompson suggests, you can setup a dual-boot solution if you actually need a Linux compatible executable. 正如Keith Thompson建议的那样,如果您确实需要Linux兼容的可执行文件,则可以设置双启动解决方案。 Remember any program compiled on Windows results in a Windows-only executable unless you have a compiler that allows for cross-compilation. 请记住,在Windows上编译的任何程序都会产生仅限Windows的可执行文件,除非您有一个允许交叉编译的编译器。

It became possible for them who use Windows 10 64 bit with new " Linux Subsystem " feature. 使用Windows 10 64位的用户可以使用新的“ Linux子系统 ”功能。 You may install gnat on it and use it to compile ELF binaries, as well as windows binaries. 您可以在其上安装gnat并使用它来编译ELF二进制文件以及Windows二进制文件。

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

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