Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would be the equivalent of Win32 API in linux?

Tags:

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.

like image 208
m4l490n Avatar asked Jan 04 '13 17:01

m4l490n


People also ask

Does Linux have an API like Windows?

No, unlike vendor-controlled platforms like Windows and OS X, Linux distributions have no single-source proprietary Linux-only API that is the universal standard default for everything from low-level file access right up to GUI interfaces.

What API does Linux use?

The Linux API is the kernel–user space API, which allows programs in user space to access system resources and services of the Linux kernel. It is composed out of the System Call Interface of the Linux kernel and the subroutines in the GNU C Library (glibc).

Is Win32 API still used?

Over the years, Microsoft has adopted it internally for the development of Office 365, Skype, and other applications. That was 16 years ago. However, Win32 still is the predominant legacy programming API. More apps out in the wild use it than anything else.

What is Win32 APIs?

Alternatively referred to as the Windows API and WinAPI, Win32 is the main set of Microsoft Windows APIs used for developing 32-bit applications. These APIs are responsible for functions in the following categories: Administration and Management - Install, configure, and service applications or systems.


2 Answers

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, see syscalls(2) for a list, which depends upon your precise Linux kernel).

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 or FLTK or POCO, and Wt for web applications, and sqlite for databases).

Some open source server software (e.g. lighttpd, exim, postgresql, etc...) can run on both Linux and Windows (of course, after recompilation)

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 or 2020, 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 and/or POCO 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.

like image 118
Basile Starynkevitch Avatar answered Oct 29 '22 21:10

Basile Starynkevitch


If you want to port an application that uses Win32 calls, your best bet might be to use WineLib. This uses the libraries underpinning Wine, but it's not the same as just running an application using Wine -- you re-compile your application as a Linux application, just using the WineLib shared libraries. It will still look like a Windows application though, unless you then modify the UI layer.

As has been said elsewhere in the answers, there's no real direct equivalent to Win32 in Linux -- different bits of Win32 are provided by different components, and sometimes you've got a choice of components. This is possible because some equivalents of parts of Win32 are implemented natively at a lower level -- for example, Win32 provides UI components, equivalents to which are available in either GTK, Qt or any number of other toolkits (like WineLib), which themselves interact with X. Just as you would usually use components from Win32 rather than drawing your own using lower-level API calls, so you'd normally use components from your high-level UI toolkit rather than using X directly.

like image 38
Andrew Aylett Avatar answered Oct 29 '22 20:10

Andrew Aylett