Programming the main function in linux

Started by
12 comments, last by Phillk6751 22 years, 5 months ago
in windows i use winmain for my graphical programs, ie, in opengl and what is the equivilant to winmain in linux, and if it depends on the GUI then lets take KDE for instance....or is winmain still winmain in linux, i think thats one of the things that isn''t compatable with other platforms in c++, right?
Advertisement
winmain() is for microsoft windows only.
i do not know if there is a graphical window-y interface for linux (i have only used the command-line unix at my college before), or how you would create windows for it if there is one...
you probably have to use main(), and then initialize the stuff for the platform''s GUI.

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
the function 'int main(int argc, char *argv[])' is the standard entry point for all C and C++ programs. Windows uses WinMain because.. um... because.. well...I guess they just don't want their programs to be portable. I'm not really sure what the reason for having a non-standard entry point is.



So, in short, use main() for linux programs. It doesn't matter if they are console or X.

Edited by - A. Buza on November 16, 2001 1:07:58 PM
so if i wanted to create an open gl window for linux i could pretty much just change the winmain function i created to main and then i would also have to find the equivilent header file to windows.h?
If you''re just looking for a very basic way to create a simple window/fullscreen opengl app in linux. I recommend you try out the SDL at http://www.libsdl.org/
I don''t know if there is an "equivalent to" windows.h.

Odds are you created a Windows class and a WindProc, right? You''ll have to drop those. I think the concepts are similar, but the calls are not.

Look up Gnome. It (and KDE) are the most used Linux Window systems. Gnome has GTK+ toolkit for developing window apps. I''m not sure what KDE''s toolkit or SDK is. Anyone?

Not really my main area, so anyone with more experience please chime in.

R.
How about downloading the working code from the NeHe tutorials for linux, that might help?...I really got to learn to do OpenGL in Linux so that i can create a game using a combonation of OpenGL and whatever general sound use i can to create it..Kinda like quak3 but its gonna be much simpler and im gonna borrow textures from quake and other FPS games.
1.) Windows uses WinMain because it needs to initialize platform-specific functionality per program. Windows programs actually have a main but it is provided by the Windows libraries, which have a prototype definition of WinMain (which must be defined to write a full-fledged Windows app.)

2.) int main(int argc, char *argv[]) is the entry point to all C/C++ programs, as mentioned above. Under Linux, this is the execution entry point of your program; unlike Windows, however, the Linux GUIs are not a part of the OS per se but rather usermode processes. You need to initialize and call their own functions (much like Win32) to use them, and in the case of QT you even have to run your code through a meta-compiler called moc.

The most popular Linux GUI toolkits are GTK/GTK+ for GNOME (but you should also look into Bonobo components, GLADE, etc) and KDE which is based on Trolltech''s QT toolkit (which is multiplatform, but butt-ugly under Windows IMO.) KDE has the nicer aesthetic, but QT is harder to program (they use a signals and slots mechanism for messages that makes MFC look like a pearl of elegance). Of course there''s Xlib and Xt, which is the toolkit for the underlying X Windows system, but they''re not terriblky full-featured or intuitive to use. There''s also toolkits for Blackbox, AfterStep, WindowMaker (WindowMaker, btw, is a really groovy environment but not as popular as KDE/GNOME) and other window managers (WMs.)

The best part? They''re completely interoperable (well, nearly.) You can run applications designed for KDE within GNOME, and they''ll have their KDE appearance so long as the user has the necessary KDE libraries installed (a must these days.) However, the apps wont be able to respond to some of the more advanced features of each environment (like GNOME hints - I once had GNOME interrupting me every 5 minutes to tell me KMail did not respond to a hint message.)

Anyway, have fun.
quote:Original post by Phillk6751
in windows i use winmain for my graphical programs, ie, in opengl and what is the equivilant to winmain in linux, and if it depends on the GUI then lets take KDE for instance....or is winmain still winmain in linux, i think thats one of the things that isn''t compatable with other platforms in c++, right?


As a couple of people seem to have mentioned, the correct version of the main variant is : int main( int argc, char *argv[]) or what ever variant of main you usually use... But if you want help with OGL & Linux, get one of the first three tutorials from nehe.gamedev.net. At the bottom of the tuts, they have a list of all compilers they have the demos running on and Linux is one of them. Use that to get you started out and you should be fine.



"And that''s the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
[Cyberdrek | ]
quote:Original post by Oluseyi
1.) Windows programs actually have a main but it is provided by the Windows libraries,


Didn''t we cover this in another thread? Its simply not true.



"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." - - Stephen Roberts
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement