[英]Easiest way to build a cross-platform application
I have read a few articles in the cross-platform tag.我已经阅读了跨平台标签中的几篇文章。 However, as I'm starting a fresh application (mostly a terminal/console app), I'm wondering about the easiest way to make it cross-platform (ie working for Linux, Mac OS X, and Windows).然而,当我开始一个新的应用程序(主要是终端/控制台应用程序)时,我想知道使它跨平台的最简单方法(即适用于 Linux、Mac OS X 和 Windows)。 I have thought about the following:我想过以下问题:
Your thoughts?你的意见? Thanks in advance for your contribution!预先感谢您的贡献!
Edit: Sounds like there are a lot of popular responses on Java and Qt.编辑:听起来有很多关于 Java 和 Qt 的流行回应。 What are the tradeoffs between these two while we're at it?我们在这两者之间有什么权衡?
Do not go the first way.不要走第一种方式。 You'll encounter a lot of problems that are already solved for you by numerous tools.您会遇到很多问题,这些问题已经由众多工具为您解决了。
Qt is an excellent choice if you definitely want C++.如果你肯定想要 C++,Qt 是一个很好的选择。 In fact, it will speed up development even if you aren't familiar with it, as it has excellent documentation and is easy to use.事实上,即使您不熟悉它,它也会加快开发速度,因为它具有出色的文档并且易于使用。 The good part about it is that it isn't just a GUI framework, but also networking, XML, I/O and lots of other stuff you'll probably need.它的优点在于它不仅是一个 GUI 框架,而且还是网络、XML、I/O 和许多您可能需要的其他东西。
If not necessary C++, I'd go with Java.如果不需要 C++,我会选择 Java。 C++ is far too low level language for most applications.对于大多数应用程序来说,C++ 是太低级的语言。 Debugging memory management and corrupt stacks can be a nightmare.调试内存管理和损坏的堆栈可能是一场噩梦。
To your edited question:对于您编辑的问题:
Use Java.使用 Java。 As much bashing as it gets/used to get, it's the best thing to get stuff working across any platform.与它得到/习惯得到的一样多的抨击,让东西在任何平台上工作都是最好的。 Sure, you will still need to handle external OS related functions you may be using, but it's much better than using anything else.当然,您仍然需要处理您可能正在使用的外部操作系统相关功能,但这比使用其他任何东西都要好得多。
Apart from Java, there are a few things you can run on the JVM - JRuby, Jython, Scala come to mind.除了 Java 之外,您还可以在 JVM 上运行一些东西 - JRuby、Jython、Scala。
You could also write with the scripting languages directly( Ruby, Python, etc ).您也可以直接使用脚本语言(Ruby、Python 等)进行编写。
C/C++ is best left for applications that demand complete memory control and high controllability. C/C++ 最适合需要完全内存控制和高度可控性的应用程序。
I'd go with the QT (or some other framework) option.我会选择 QT(或其他一些框架)选项。 If you went with the first you'd find it considerably harder.如果你选择第一个,你会发现它要困难得多。 After all, you have to know what to put into the various conditionally compiled sections for all the platforms you're targeting.毕竟,您必须知道在针对您所针对的所有平台的各种条件编译部分中放入什么内容。
I would also suggest Github's electron which allows to build cross platform desktop applications using NodeJs and the Google's Chromium.我还建议使用 Github 的电子,它允许使用 NodeJs 和谷歌的 Chromium 构建跨平台桌面应用程序。 The only drawback for this method is that an electron application run much slower than a native C++ application due to the abstraction layers between Javascript and native C++.这种方法的唯一缺点是,由于 Javascript 和本机 C++ 之间的抽象层,电子应用程序的运行速度比本机 C++ 应用程序慢得多。
I would suggest using a technology designed for cross-platform application development.我建议使用专为跨平台应用程序开发设计的技术。 Here are two technologies I know of that -- as long as you read the documentation and use the features properly -- you can build the application to run on all 3 platforms:以下是我所知道的两种技术——只要您阅读文档并正确使用这些功能——您就可以构建在所有 3 个平台上运行的应用程序:
Of course, there is always the web.当然,网络总是存在的。 I mostly use web applications not just for their portability, but also because they run on my Windows PC, my Ubuntu computer, and my Mac.我主要使用 Web 应用程序不仅是因为它们的可移植性,还因为它们可以在我的 Windows PC、我的 Ubuntu 计算机和我的 Mac 上运行。
We mainly build web applications because the web is the future.我们主要构建 Web 应用程序,因为 Web 是未来。 Local applications are viewed in my organization as mostly outdated, unless there is of course some feature or technology the web doesn't yet support that holds that application back from being fully web-based.在我的组织中,本地应用程序被视为大部分已过时,除非当然有某些功能或技术 Web 尚不支持,使该应用程序无法完全基于 Web。
If you're making a console app, you should be able to use the same source for all three platforms if you stick to the functions defined in the POSIX libraries.如果您正在制作控制台应用程序,并且坚持使用 POSIX 库中定义的函数,那么您应该能够对所有三个平台使用相同的源代码。 Setting up your build environment is the most complicated part, especially if you want to be able to build for multiple platforms out of the same source tree.设置构建环境是最复杂的部分,特别是如果您希望能够从同一个源代码树中为多个平台构建。
I'd say if you really want to use C++, QT is the easiest way for cross-platform application, I found myself using QT when I need an UI even though QT has a large set of library which makes pretty much everything easier in C++.我想说如果你真的想使用 C++,QT 是跨平台应用程序的最简单的方法,我发现自己在需要 UI 时使用 QT,即使 QT 有大量的库,这使得 C++ 中的一切变得更容易.
If you don't want to use QT then you need a good design and a lot of abstraction to make cross-platfform application.如果你不想使用 QT,那么你需要一个好的设计和大量的抽象来制作跨平台的应用程序。
However I'm using more and more Python bindinq to QT for medium size application.但是,我越来越多地将 Python bindinq 用于 QT 以用于中等规模的应用程序。 If you are working on a console application and you know a bit of python, you might find Python scripting much more comfortable than C++.如果您正在开发控制台应用程序并且了解一些 Python,您可能会发现 Python 脚本比 C++ 更舒适。 It keeps the time comsuming stuff away to be able to focus on your application.它可以节省时间,从而能够专注于您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.