new_perl
new_perl

Reputation: 7735

What's the entry point of GUI program in linux?

In windows it's WinMain,

what's it in linux?

Or is it still main?

Upvotes: 3

Views: 1283

Answers (3)

MarkR
MarkR

Reputation: 63538

Yes it is always main().

Linux, per se, does not distinguish between GUI and non-GUI programs. It doesn't have a flag in the executable to say "this is a console app" or "this is a window app".

Strictly speaking, the entry point is NOT main(), but _start or something. However, if you're linking with the standard C library or some variant of it, it tends to be main() by convention in the C language.

Upvotes: 0

paxdiablo
paxdiablo

Reputation: 881553

It depends entirely on the GUI library that you're using. The entry point for a C program (in hosted mode) is always main (usually, it's in the C startup code which configures things and then calls main which is where your code starts.

Some environments provide their own version of main to set things up before calling your code. However, Qt and KDE (as two examples) still uses main and you're required to set the envirnment up yourself.

Upvotes: 1

Greg Hewgill
Greg Hewgill

Reputation: 993183

The Windows PE (Portable Executable) format has a flag in the header that states whether the executable is console or windowed. Depending on which it is, Windows will allocate a console window for the application, or not. This also determines whether the entry point is main or WinMain.

The Linux ELF format does not have a similar flag. The entry point is always main. The concept of "console window" is entirely different in Linux.

(Note that the above simplifies the issue somewhat, since the entry point you're talking about is where the user code starts. The compiler/linker always supplies some runtime library startup code that runs before your user entry point is called, which is where the real entry point is.)

Upvotes: 3

Related Questions