最简单的方法来构建跨平台应用程序 [英] Easiest way to build a cross-platform application

查看:130
本文介绍了最简单的方法来构建跨平台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在跨平台代码中阅读了几篇文章。然而,当我开始一个新的应用程序(大多是终端/控制台应用程序),我想知道使它跨平台(即工作在Linux,Mac OS X和Windows)的最简单的方法。我已经考虑过以下内容:




  • 在我的代码中添加各种宏/标签,为每个操作系统构建不同的二进制可执行文件

  • 使用Qt平台开发一个跨功能应用程序(虽然GUI和平台组件会增加更多的开发时间,因为我不熟悉Qt)



您的想法?感谢您的贡献!



编辑:听起来像Java和Qt上有很多热门反应。

解决方案

不要走第一条路。你会遇到很多已经由众多工具解决的问题。



如果你肯定想要C ++,Qt是一个很好的选择。事实上,它会加快开发,即使你不熟悉它,因为它有优秀的文档和易于使用。好的部分是它不只是一个GUI框架,而且还包括网络,XML,I / O和很多其他你可能需要的东西。



如果不需要C ++,我会用Java。 C ++对于大多数应用程序来说是太低级的语言。调试内存管理和损坏的堆栈可能是一场噩梦。



对您编辑的问题




  • 显而易见的一个:Java有垃圾回收,C ++没有。这意味着在Java中没有内存泄漏(除非你在JVM中计算可能的错误),不需要担心悬挂指针等。

  • 另一个明显的问题是:在C ++中使用#ifdefs的依赖代码。在Java中它是一个真正的痛苦。有JNI,但根本不容易使用。

  • Java对异常有非常广泛的支持。虽然C ++也有异常,但是Qt不使用它们,并且在Java中生成异常的一些东西会让你有C ++的内存损坏和崩溃(想想缓冲区溢出)。

  • 一次,无处不在。重新编译C ++程序对于许多平台可能是令人望而生畏。 Java程序不需要重新编译。

  • 这是开放的辩论,但我认为Java有更广泛和良好定义的库。抽象级别一般较高,接口更干净。它支持更多有用的东西,如XML模式等。我不能想到一个特性,它存在于Qt,但在Java中缺席。也许多媒体或东西,我不确定。

  • 现在这两种语言都很快,所以性能通常不是一个问题,但Java可以是一个真正的记忆。

  • 最不明显的一点是:C ++比Java更具可移植性。一个例子是FreeBSD操作系统,它在前一段时间对Java的支持非常差(不知道是否还是这样)。 C ++ / Qt在那里完美工作。如果您计划支持各种Unix系统,C ++可能是更好的选择。


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 (i.e. working for Linux, Mac OS X, and Windows). I have thought about the following:

  • adding various macro/tags in my code to build different binary executables for each operating system
  • use Qt platform to develop a cross-functional app (although the GUI and platform component would add more development time as I'm not familiar with Qt)

Your thoughts? Thanks in advance for your contribution!

Edit: Sounds like there are a lot of popular responses on Java and 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++. 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.

If not necessary C++, I'd go with Java. C++ is far too low level language for most applications. Debugging memory management and corrupt stacks can be a nightmare.

To your edited question:

  • The obvious one: Java has garbage collection, C++ doesn't. It means no memory leaks in Java (unless you count possible bugs in JVM), no need to worry about dangling pointers and such.
  • Another obvious one: it is extremely easy to use platform-dependent code in C++ using #ifdefs. In Java it is a real pain. There is JNI but it isn't easy to use at all.
  • Java has very extensive support of exceptions. While C++ has exceptions too, Qt doesn't use them, and some things that generate exceptions in Java will leave you with corrupt memory and crashes in C++ (think buffer overflows).
  • "Write once, run everywhere." Recompiling C++ program for many platforms can be daunting. Java programs don't need to be recompiled.
  • It is open to debate, but I think Java has more extensive and well-defined library. The abstraction level is generally higher, the interfaces are more clean. And it supports more useful things, like XML schemas and such. I can't think of a feature that is present in Qt, but absent in Java. Maybe multimedia or something, I'm not sure.
  • Both languages are very fast nowadays, so performance is usually not an issue, but Java can be a real memory hog. Not extremely important on modern hardware too, but still.
  • The least obvious one: C++ can be more portable than Java. One example is FreeBSD OS which had very poor support for Java some time ago (don't know if it is still the case). C++/Qt works perfectly there. If you plan on supporting a wide range of Unix systems, C++ may be a better choice.

这篇关于最简单的方法来构建跨平台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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