tags:

views:

202

answers:

7

I'm moving from windows programming (By windows programming I mean using Windows API) to Linux Programming.

For programming Windows, the option we have is Win32API (MFC is just a C++ wrapper for the same).

I want to know if there is something like Linux API (equivalent to WINAPI) that is exposed directly to the programmer? Where can I find the reference?

With my little knowledge of POSIX library I see that it wraps around part of Linux API. But what about creating GUI applications? POSIX doesn't offer that. I know there are tons of 3rd party Widget toolkits like gtk, Qt etc. But I don't want to use the libraries that encapsulates Linux API. I want to learn using the "Core Linux API".

If there are somethings that I should know, please inform. Any programmer who is familiar with both Windows & Linux programming, please map the terminologies of Linux world so that I can quickly move on.

Any resources (books,tutorials,references) are highly appreciated.

+5  A: 

I think you're looking for something that doesn't exactly exist. Unlike the Win32 API, there is no "Linux API" for doing GUI applications. The closest you can get is the X protocol itself, which is a pretty low level way of doing GUI (it's much more detailed and archaic than Win32 GDI, for example). This is why there exist wrappers such as GTK and Qt that hide the details of the X protocol.

The X protocol is available to C programs using XLib.

Greg Hewgill
Yep. Whilst using the Win32 API directly to code lightweight applications is very feasible, all you'll get from coding directly to XLib is painful code and badly-behaved apps. Whilst a lot of work has gone into making X less bad since the emphasis on desktop Linux, it's still pretty nasty. Avoid.
bobince
claws
@claws: Win32 GDI is not part of the Windows kernel as such. Similarly, Xlib is definitely not part of the Linux kernel, Xlib is just a bunch of code that you compile and link into your application.
Greg Hewgill
@claws: In Windows the native API is the actual interface to the Windows NT system. In Windows NT, the Win32 API is just a layer above the native API. Because the NT kernel has nothing to do with the GUI, the Native API doesn't include any graphics-related services. The Win32 subsystem is the gateway to all user-interfaces in Windows. It is important to know that the components considered in the Win32 subsystem are not responsible for the entire Win32 API, only for the USER and GDI portions of it codeproject.com/KB/system/Win32.aspx
claws
claws
+2  A: 

What you must understand is that Linux is very bare as to what is contained within it. The "Core" Linux API is POSIX and glibc. Linux is NOT graphical by default, so there is no core graphics library. Really, Windows could be stripped down to not have graphics also and thus not have parts of the win32 API like GDI. This you must understand. Linux is very lightweight compared to Windows.

For Linux there are two main graphical toolkits, GTK and Qt. I myself prefer GTK, but I'd research both. Also note that GTK and Qt exist for Windows to, because they are just wrappers. If you go take a look at the X protocol code for say xterm, you'll see why no one tries to actually creating graphical applications on top of it.

Oh, also SDL is pretty nice, it is pretty bare, but it is nice if your just needing a framebuffer for a window. It is portable between Linux and Windows and very easy to learn. But it will only stretch so far..

Earlz
`glibc` is a standard C library.its not specific to linux. So, the "Core Linux API" is just POSIX library? I thought posix wraps only subset of the API.
claws
Well, POSIX is basically a standard to tell how the standard library (and a few extensions) must behave and what functions must exist to be compliant.. Of course there is more than just the glibc and Posix, but there isn't all that much... the only functions I can think of are like for loading kernel modules and such. Are sockets covered in Posix?
Earlz
A: 

There is also the docs for the two different desktop platforms: Gnome and KDE that might help you down that road.

Kevin Won
+1  A: 

Linux and win aren't quite as different as it looks.

On both systems there exists a kernel that is not graphical.

It's just that Microsoft doesn't document this kernel and publishes an API that references various different components.

On Unix, it's more transparent. There really is a (non-GUI) kernel API and it is published. Then, there are services that run on top of this, optionally, and their interfaces are published without an attempt to merge them into an imaginary layer that doesn't really exist.

So, the lowest GUI level is a the X Window System and it has a lowest level library called Xlib. There are various libraries that run on top of this one, as you have noted.

DigitalRoss
claws
In Windows the native API is the actual interface to the Windows NT system. In Windows NT, the Win32 API is just a layer above the native API. Because the NT kernel has nothing to do with the GUI, the Native API doesn't include any graphics-related services. The Win32 subsystem is the gateway to all user-interfaces in Windows. It is important to know that the components considered in the Win32 subsystem are not responsible for the entire Win32 API, only for the USER and GDI portions of ithttp://www.codeproject.com/KB/system/Win32.aspx
claws
+1  A: 

This is going to sound insane since you're asking about "serious" stuff like C++ and C (and the "core linux API"), but you might want to consider building in something else. For instance:

  • Java Swing (many people love it! Others hate it and call it obsolete)
  • Mono GTK# (C# or VisualBasic or whatever you want, lots of people say it's pretty cool, but they're not not that many people)
  • Adobe AIR (ActionScript, you might hate it)
  • Titanium (totally new and unproven, but getting a lot of buzz in the iPhone world, at least)

And many other possibilities, some of which let you work on multiple platforms at once.

Sorry if this answer is not at all what you're looking for. The "real" answers on Linux are "pick a toolkit," which is also no answer at all :)

Yar
A: 

Have a look at Cairo. This something roughly similar to GDI+ and is under the hood of some of of the few usable GUI programs for Linux i.e. Firefox or Eclipse (SWT). It wraps most the natsy and ancient Linux stuff for you into a nice API that runs on most Linux installations without locking you into a entire subsystems like GTK or QT.

x4u
+2  A: 

I would highly recommended looking at the QT/C++ UI framework, it's arguably the most comprehensive UI toolkit for any platform.

We're using it at work developing cross platform apps that run on windows, osx and linux.

It also runs on Nokia's smart phone Operating System Maemo which has recently been merged with Intel's Moblin Linux OS, now called MeeGo.

mythz