29

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.

m4l490n
  • 1,592
  • 2
  • 25
  • 46
  • [Mainsoft](http://www.mainsoft.com/content/mainsoft-unix-and-linux-overview) provides one possibility (albeit, at a serious price). – Jerry Coffin Jan 04 '13 at 17:17
  • 3
    Qt is an abstraction layer. It has platform specific implementations that map Qt commands to the underlying native operation. It depends upon which win32 api call you want to port. Some are so windows specific that they are unlikely to work anywhere else. – Chriseyre2000 Jan 04 '13 at 17:18
  • 2
    Win32 is a massive suite of semi-related libraries for everything from GUI elements to 3D graphics to socket manipulation. Linux is far more modular, and you'll probably want to pick and choose several libraries to use in porting your project. – user229044 Jan 04 '13 at 17:21
  • @meagar: WinAPI is split in a modular way too according to header files. eg. gdi, user, kernel, etc. – Mike Kwan Jan 04 '13 at 17:21
  • @MikeKwan ... Yes, I know? My point stands as written. OP asks for an "equivalent library" to the Win32 API, not one specific sub-portion of the API. – user229044 Jan 04 '13 at 17:22
  • @meagar When was 3D graphics introduced to the Win32 API? – IInspectable Jan 04 '13 at 17:22
  • 1
    @meagar: How does that make Linux 'far more modular' then? – Mike Kwan Jan 04 '13 at 17:23
  • @MikeKwan I meant Linux is more modular than *Windows*, not that Linux APIs are more modular than Windows APIs. There is no standard window manager for Linux, for example, and choice of a socket library and a GUI library can be made in relative isolation. – user229044 Jan 04 '13 at 17:25
  • @Tim Win32 contains an implementation of OpenGL, afaik. – user229044 Jan 04 '13 at 17:32
  • @Chriseyre2000 - What do you mean with "It has platform specific implementations that map Qt commands to the underlying native operation" What I try to understand is for example what API of functions are at the bottom of QT that makes it multi-platform. For instance, If I take a 32 bit microcontroller with a good hardware graphics controller like the LPC1788 what would be the Win32 API equivalent, in terms of the LPC1788, that I should provide to make Qt work for this MCU? – m4l490n Jan 04 '13 at 17:37
  • 1
    My larger point is that nobody can recommend a *single library* to port your app against which provides all the functionality you *might* be using from the Win32 API. Win32 is meant to be the single point of interaction between your application and the operating system, and it can provide this because every aspect of the operating system is fixed to some standard. There are too many variable components of a Linux system for there to be a generic "Sure, use *this* library" answer. The answer to "What would be the equivalent of Win32 API in linux?" is there *isn't one*. – user229044 Jan 04 '13 at 17:39
  • If you want to write cross-platform applications take a look at wxWidgets (http://www.wxwidgets.org/). – Benny Hill Jan 04 '13 at 18:21
  • Possible duplicate of [Is there a Core Linux API analogous to Windows WINAPI, in particular for creating GUI applications?](http://stackoverflow.com/questions/2277381/is-there-a-core-linux-api-analogous-to-windows-winapi-in-particular-for-creatin) – Mahmudul Haque Apr 09 '17 at 19:49

2 Answers2

28

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.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
7

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.

Andrew Aylett
  • 39,182
  • 5
  • 68
  • 95