开发者

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

开发者 https://www.devze.com 2023-04-12 02:45 出处:网络
In windows it\'s WinMain, what\'s it in linux? 开发者_开发知识库 Or is it still main?The Windows PE (Portable Executable) format has a flag in the header that states whether the executable is console

In windows it's WinMain,

what's it in linux?

开发者_开发知识库

Or is it still main?


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.)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号