在Linux中相当于Win32 API? [英] What would be the equivalent of Win32 API in linux?

查看:117
本文介绍了在Linux中相当于Win32 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想知道Windows和Linux中的API函数之间是否存在一一对应的关系,也不想知道每个API函数.

我只想了解两点基本知识:

  1. 我想了解为什么Qt平台不独立
  2. 我想知道我应该在linux中使用什么API来移植使用Win32 API编程的应用程序,换句话说,移植到Win32 API级别.

我知道这不切实际,但我想知道这种等效性.

解决方案

您需要了解什么系统调用是.在Linux上,它们是最低的用户陆地API(相比之下,叉子(2) execve(2) open(2)进程在Linux和Windows上都大不相同.)

别忘了Linux是免费软件,您可以深入研究Linux上使用的每个功能的源代码.阅读,搜索,改进.....

阅读简介(2)手册页,以及其他几个手册页(尤其是 intro(3)等.).另请参阅高级Linux编程高级Unix编程.

一些库尝试排除这些因素,并为Posix(例如Linux)和Windows提供通用的抽象.特别是 Qt (还有Gtk).

如果您对图形界面感兴趣,请了解 X11 的重要作用(请注意, X11服务器离屏幕和键盘最近;大多数图形应用程序都是X11客户端).在2016年,X11往往会被 Wayland 取代(但您不会注意到该实现详细"-一个非常重要的实现-如果您针对Qt或GTK进行编码)

如果您仅使用Qt调用(未记录为特定于Linux或Windows的代码)以及标准C ++函数编写应用程序,则应将其从Linux移植到Windows,反之亦然.

I don't want to know if there is a one-to-one equivalence between API functions in windows and linux, neither want to know every API function.

I just want to know this for two basic things:

  1. I want to understand why is Qt platform independent
  2. I want to know what API should I use in linux to port an application programmed with the Win32 API, or in other words, at Win32 API level.

I know that this is not practical but I want to know this equivalence.

解决方案

You need to understand what syscalls are. On Linux, they are the lowest possible user land API (in contrast Win32 API probably mixes real kernel syscalls with some libraries functions. libc also does such mix on Linux). fork(2), execve(2), open(2), pipe(2), mmap(2), read(2), poll(2), close(2), dup2(2), sigaction(2) are important syscalls (but there are about 300 of them).

Don't expect each windows functionality to be available on Linux (and vice versa). Don't even think of such an equivalent. Get a different mindset on Linux. (In particular, processes are very different on Linux and on Windows).

Don't forget that Linux is free software, and you can dive into the source code of every function you are using on Linux. Read it, search it, improve it.....

Read the intro(2) man page first, and several other man pages (notably syscalls(2), intro(3) etc...). Read also e.g. Advanced Linux Programming and Advanced Unix Programming.

Some libraries try to factor out and provide a common abstraction for both Posix (e.g. Linux) and Windows. In particular Qt (and also Gtk).

If you are interested about graphical interface, understand the important role of X11 (notice that the X11 server is nearest to screen & keyboard; most graphical applications are X11 clients). In 2016, X11 tend to be superseded by Wayland (but you won't notice that implementation "detail" - a really major one - if you code against Qt or GTK)

If you write an application using only Qt calls (those not documented as being specific to Linux or Windows) in addition of standard C++ functions, it should be source portable from Linux to Windows and vice versa.

这篇关于在Linux中相当于Win32 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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