C++ 用于多平台开发的 API

发布于 2024-07-29 23:14:10 字数 160 浏览 6 评论 0原文

我想学习 C++ 以在各种平台上工作(主要是 Linux 和 Windows)。 我遇到过一些解决方案,例如 Boost C++ 库、Qt 工具包等,可用于编写可在两个平台上编译的程序。

我想从社区中了解您会参考使用什么类型的库,以及你们中的任何人以前是否有过此类多平台编程的经验。

I want to learn C++ to work on various platform (primarily, Linux and Windows). I have come across few solutions like the Boost C++ library, Qt toolkit, etc that can be used to write programs which will compile on both the platforms.

I want to know from the community, what type of library would you refer to use and if any of you had experience with this type of multi-platform programming before.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

如痴如狂 2024-08-05 23:14:22

标准 C++ 程序可以编译并可移植,即可以在多种平台上工作。 为了确保保持代码干净,最好的选择是使用几个不同的编译器并使用所有编译器检查您的代码,同时强制执行完全标准一致性(使用诸如 -std= 之类的选项 -std=例如,code>g++)并编写无警告代码(对于 g++ 使用 -W -Wall -Werror 等选项,它会发出错误而不是警告)。 编译器的确切选择取决于您,但如果您主要是学习,我建议使用:

  • g++(免费,开源)
  • Intel编译器(免费用于Linux上的非商业用途)
  • 也许MSVC++

也,如果您确实必须在项目中使用特定于编译器或目标的代码,请务必将其抽象化,以便将其全部聚集在一个位置,并且对其余代码隐藏。

现在,如果您想使用 STL 之外的其他内容,那么您需要通过考虑它们所测试的编译器和平台的范围来选择您的库(并且,如果文档没有说明,这是一个坏兆头)。 具体的选择取决于您到底想要做什么,但 Boost(作为一个强大的、广泛的库,可以解决许多常见问题)和 Qt(最新版本;用于 GUI 编程)是不错的选择。 对于数值、科学编程,BLAS/LAPACK(和/或其并行版本,BLACS 和 Scalapack)直接或通过包装 C++ 类广泛使用,如 Boost(用于 BLAS)中所示; 通常还需要一个好的 FFT 库(如果 GPL 许可证不是您的负担,FFTW 就很好)。

Standard C++ programs will compile and be portable, i.e. work across a large range of platforms. To be sure that you are keeping code clean, your best bet is to get a few different compiler and check your code with all of them, while enforcing full standard conformance (with options like -std= for g++, for example) and writing warning-free code (with options such as -W -Wall -Werror for g++, which emits errors instead of warnings). The exact choice of compilers is up to you, but if you're mostly learning, I advice using:

  • g++ (free, open source)
  • the Intel compiler (free for noncommercial use on Linux)
  • maybe MSVC++

Also, if you really have to use compiler- or target-specific code in your projects, be sure to abstract it so it's all gathered in one place, and hidden from the rest of your code.

Now, if you want to use more than the STL, then you need to choose your libraries by considering the range of compilers and platforms they're tested against (and, if the documentaiton doesn't state it, it's a bad omen). The detailled choice depends on what exactly you want to do, but Boost (as a robust, wide-ranging library for many common issues) and Qt (a recent version; for GUI programming) are good choices. For numerical, scientific programming, BLAS/LAPACK (and/or their parallel versions, BLACS and Scalapack) are very widely used, directly or through wrapper C++ classes as can be found in Boost (for BLAS); a good FFT library is also often needed (FFTW is good if its GPL licence is not a burden for you).

童话里做英雄 2024-08-05 23:14:20

我打算用 C++ 进行一些跨平台开发,而您不想维护不同的构建系统(Makefile、Visual Studio 项目等),有几种工具可以帮助您。

我个人使用的是CMake。 它支持 Linux 和 Unix Flavors、Windows 和 Mac/OS。 实际上,一些开源项目(例如 KDE)都使用它。 但还有其他选项,例如 Scons

I for are going to do some cross platform development in C++ an you don't want to maintain different build systems (Makefiles, Visual Studio Projects, etc) there are several tools out there that can help you.

The one I personally use is CMake. It supports Linux and Unix Flavours, Windows and Mac/OS. Actually several open source projects, like KDE, use it. But there are others options like for instance Scons.

哆兒滾 2024-08-05 23:14:18

正如其他发帖者提到的,我会推荐 Qt 和 Boost 进行跨平台开发。 我曾尝试过 gtkmm,它是 GTK+ 的一个薄 C++ 包装器,但对它并不满意,部分原因是它不是原生 C++ 库,而且与 Qt 相比,文档很差。 除此之外,Qt 还具有非常好的开发环境,包括易于编写的 make 替代 qmake 和 GUI 设计器。

Like other posters have mentioned, I would recommend Qt and Boost for cross-platform development. I had tried gtkmm which is a thin C++ wrapper around GTK+, but was not satisfied with it partly because it's not a native C++ library and documentation is poor compared to Qt. Besides that, Qt comes with very nice development environment including a easy-to-write make alternative qmake and a gui designer.

紫罗兰の梦幻 2024-08-05 23:14:18

核心 C++ 标准和 STL 几乎已经是跨平台的了。 通常只有 GUI 和硬件访问内容需要库。

我已经使用 GTK+ 作为 GUI 工具包,它也相当不错,尽管您需要在 Windows 上安装 glib 和其他一些东西。

RtAudio 非常适合跨平台音频 I/O。

Windows 和 Linux 之间的底层网络/套接字内容基本相同,您可以自己编写一个非常轻量级的层来处理任何差异。 我没有任何高级网络库的经验。

我还喜欢用于跨平台 2D 图形类型内容的 SFML(简单快速媒体库)。 确实非常好。


不过,我建议,如果您只是学习 c++,那么您最好不要查看 Boost(或者实际上任何这些工具包),直到您了解了了解基础知识 - 例如,编写几个基本的控制台应用程序。

如果您只想学习 C++,以便进行多平台 开发,请注意,还有许多其他语言和相关工具包可能更合适,具体取决于您正在编写的应用程序。

在不知道您计划开发的应用程序类型的情况下,很难说 C++(或 C 或 Python 或其他)是否是最好的主意。 就我个人而言,我通常会使用 Python + PyGTK 来构建跨平台 GUI 应用程序,使用 C# 来构建纯 Windows 应用程序。 您始终可以插入 C/C++ 来替换任何运行速度太慢的组件。

The core C++ standard and the STL are pretty much cross platform already. Its usually only the GUI and hardware access stuff that requires libraries.

I have used GTK+ as a GUI toolkit and it's pretty good too, although you need to install glib and some other stuff on windows.

RtAudio is nice for cross-platform audio I/O.

The low level networking/sockets stuff is largely the same between windows and linux, you could write a very lightweight layer yourself to handle any differences. I don't have any experience with higher-level networking libraries.

I also like the SFML (simple fast media library) for cross-platform 2d graphics type stuff. It's very nice indeed.


I would suggest, however, that if you are just learning c++ then you're probably better off not looking at Boost (or indeed any of these toolkits) until you've got your head around the basics - by writing a couple of basic console applications, for example.

If you want to learn c++ only so you can do multi-platform dev, be aware that there are many other languages and associated toolkits that may be more suitable, depending on the app you're writing.

Without knowing the type of app you're planning on developing, its hard to say whether C++ (or C or Python or whatever) is the best idea. Personally, I generally turn to Python + PyGTK for crossplatform GUI apps and C# for windows-only apps. You can always plug C/C++ in to replace any components that are running too slowly.

那小子欠揍 2024-08-05 23:14:16

如果您正在做任何类型的 GUI 工作,我强烈推荐 Qt; 如果您不熟悉的话,它甚至非常有用,因为它还具有经过深思熟虑的网络/数据库/容器/等 API。 它是一个设计精良的 API,并且非常易于使用。

I highly recommend Qt if you are doing any sort of GUI work; it's even quite useful if you aren't, since it has well-thought out networking/database/container/etc APIs also. It's a very well designed API and very easy to use.

梦行七里 2024-08-05 23:14:15

您没有指定任何特定类型的库,但如果您只想要一般性推荐,我不得不说 wxWidgets 是一个优秀的跨平台 GUI 库。

它具有一些很棒的功能,例如以运行它的操作系统的本机外观和感觉呈现 GUI,并且并不是特别难学。 它提供了一个用于跨 Win/Mac/Linux 以及 WinCE 等其他 GUI 编写的 API。

我强烈推荐它用于跨平台 GUI 工作。

请访问 http://www.wxwidgets.org/ 查看

You didn't specify any partuclar type of library, but if you just want a general recommendation I have to say wxWidgets is an excellent cross platform GUI library.

It has some great features like rendering the GUI in the native look and feel of the operating system it's running on, and is not particularly hard to learn. It offers a single API for GUI writing across Win/Mac/Linux, plus others like WinCE.

I highly recommend it for cross platform GUI work.

Check it out at http://www.wxwidgets.org/

墟烟 2024-08-05 23:14:14

这取决于你要做什么。 如果您需要编写严格的命令行实用程序来处理文本,QtwxWidgets 可能不合适。 您的应用领域到底是什么?

科学计算是我的专业领域。 其中这些都是很棒的多平台 API:

并行编程

数值算法

高性能文件 I/O

It depends on what you're going to do. If you need to write a strictly command-line utility to process text, Qt or wxWidgets might be inappropriate. What exactly is your application field?

Scientific computing is my field of expertise. in which these are great multi-platform APIs:

Parallel Programming

Numerical Algorithms

High-performance file I/O

Visualization

独享拥抱 2024-08-05 23:14:12

使用 QtBOOST C++ 库。 它们都是免费的并且质量非常高。 另外,至少对我个人来说,我发现 Qt 比 wxWidgets 更直接、更容易学习、更简单。

Use Qt and the BOOST C++ Libraries. They are both free and very high quality. Also, at least for me personally, I found Qt to be much more straightforward, easy to learn, and simpler than wxWidgets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文