用 C 编写跨平台应用程序 [英] Writing cross-platform apps in C

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

问题描述

在用 C 编写跨平台应用程序时最应该记住什么?目标平台:基于 32 位 Intel 的 PC、Mac 和 Linux.我特别在寻找 Jungle Disk 在其 USB 桌面版 (http://www.jungledisk.com/desktop/download.aspx )

What things should be kept most in mind when writing cross-platform applications in C? Targeted platforms: 32-bit Intel based PC, Mac, and Linux. I'm especially looking for the type of versatility that Jungle Disk has in their USB desktop edition ( http://www.jungledisk.com/desktop/download.aspx )

这种类型的开发有哪些技巧和陷阱"?

What are tips and "gotchas" for this type of development?

推荐答案

我维护了一个 ANSI C 网络库多年,该库已移植到近 30 种不同的操作系统和编译器.该库没有任何 GUI 组件,这使它变得更容易.我们最终将任何跨平台不一致的例程抽象到专用源文件中,并在这些源文件中适当地使用#defines.这使每个平台调整的代码与库的主要业务逻辑隔离开来.我们还广泛使用了 typedef 和我们自己的专用类型,以便我们可以根据需要轻松地根据平台更改它们.这使得移植到 64 位平台变得相当容易.

I maintained for a number of years an ANSI C networking library that was ported to close to 30 different OS's and compilers. The library didn't have any GUI components, which made it easier. We ended up abstracting out into dedicated source files any routine that was not consistent across platforms, and used #defines where appropriate in those source files. This kept the code that was adjusted per platform isolated away from the main business logic of the library. We also made extensive use of typedefs and our own dedicated types so that we could easily change them per platform if needed. This made the port to 64-bit platforms fairly easy.

如果您正在寻找 GUI 组件,我建议您查看 GUI 工具包,例如 WxWindows 或 Qt(它们都是 C++ 库).

If you are looking to have GUI components, I would suggest looking at GUI toolkits such as WxWindows or Qt (which are both C++ libraries).

这篇关于用 C 编写跨平台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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