(C / C ++)如何生成可在Windows和Linux上运行的可执行文件? [英] (C/C++) How to generate executable file that can run on both Windows and Linux?

查看:582
本文介绍了(C / C ++)如何生成可在Windows和Linux上运行的可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手。据我所知,在Linux中编译的程序应该不能在Windows中运行。因此,如果要在两个平台上运行相同的程序,则需要在两个平台上编译源代码,并创建2个不同的可执行文件。

I'm new in programming. From what i know, a program that is compiled in Linux should not be able to run in Windows. So, if we want to run the same program in both platform, we need to compile the source code under both platform, and create 2 different executable files.

最近我是研究开放源代码,跨平台的Java GUI应用程序的源代码。我很惊讶地发现该GUI应用程序的后端引擎是一个由C ++代码生成的小型可执行文件。无论用户在Windows或Linux中使用该应用程序,Java GUI都将在bin文件夹中调用相同的可执行文件。

Recently I am studying the source code of an open source, cross-platform Java GUI application. I'm surprised to find that the backend engine of that GUI application is a small executable file generated from C++ codes. No matter users use that application in Windows or Linux, the Java GUI will call the same executable file in the bin folder.

我只想知道,该可执行文件如何文件可以在Windows和Linux上运行吗?

I just want to know, how can that executable file run on both Windows and Linux?

我还想创建一个使用C ++程序作为引擎的跨平台Java GUI应用程序。该C ++程序仅适用于Linux。我搜索了一段时间,发现需要使用Cygwin将其移植到Windows。但是,如果我使用Cygwin,我最终将拥有2个不同的可执行文件。

I'm also interested to create a cross-platform Java GUI application using a C++ program as the engine. That C++ program is only available for Linux only. I've been googling for a while and i found that I need to use Cygwin to port it to Windows. However, if i use Cygwin, i will end up having 2 different executable files.

如何将Windows可执行文件与Linux可执行文件结合在一起?可以生成一个可以在两个平台上运行的可执行文件吗?

How can i combine the Windows executable file with the Linux executable file? Is it possible to generate a single executable file that can run on both platform?

谢谢。

推荐答案

无法从C ++源代码编译一个本机可执行文件,该文件可在不同平台上工作。我不相信您会在第二段中声明在Windows和Linux上运行相同的可执行文件。

There is no way to have a single native executable compiled from C++ source that works on different platforms. I don't believe you that the same executable file is run on Windows and Linux, as you state in your second paragraph.

这篇关于(C / C ++)如何生成可在Windows和Linux上运行的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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