m4l490n m4l490n - 1 year ago 111
Linux Question

What would be the equivalent of Win32 API in linux?

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.

Answer Source

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.