Sign in to follow this  

Application Programming

This topic is 2547 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I've recently quit being an armchair designer by deciding to do something and learn C++. In the process, I've had a few questions about programming in general, and I figure someone here would know the answer:

So, in order to program in C++, it seems that you have to have a C++ complier installed to translate your code into machine code. So how then do professional applications/ games written in C++ work? If I haven't already installed a compiler before now, how have I been able to run C++ games? Do professional applications come written in machine code already?

I know this is probably a very basic question, but I'm curious now how it works. I've only ever run things from the command line before, so I know very little about making run-able applications.

Thanks for your help, I'm looking forward to learning more from this forum.
-Humble Hobo (from the GD forum)

Share this post


Link to post
Share on other sites
Quote:
If I haven't already installed a compiler before now, how have I been able to run C++ games? [b]Do professional applications come written in machine code already?[b]


Yep, this is correct. The programs you buy/download are already made to work for your particular machine, assuming you run the correct version. They contain OS-specific instructions. At the most you may just need runtime libraries to help the programs run (these are the DLLs in Windows or .so files in Linux). This is why native .exes on Windows won't work on other operating systems unless you use a layer of abstraction like Wine or a virtual machine.

To put it simply, program code can be complied with different configurations as to the target OS and CPU architecture that it is made for, and the compiler makes the machine code to be compatible with a machine that has that particular OS and type of CPU. There are many more compiler settings, but these are the biggest ones that determine the compatibility with the desired platform.

Share this post


Link to post
Share on other sites
Thanks, that makes sense.

So in order to share an application I make with someone, I need to compile it, then essentially give them the pre-compiled files? This is a bit of a tangent, but I imagine at some point I'll learn how to bundle pre-compiled files into a single clickable icon that runs the program for them. I'm curious how the general logistics of making applications works.

Share this post


Link to post
Share on other sites
Yep, you basically give the compiled files (aka "binaries") to the end user. The process of installing software (on platforms like Windows where installers are common) essentially involves copying over all the binaries and dependencies (DLLs/.so's) that are needed to run the software.

Occasionally on Unixes you'll run into software that only comes in source form, and you have to compile it yourself as a user to run it; but on Mac/Windows this is pretty rare.

Share this post


Link to post
Share on other sites
Alright. So now for my final question about app compiling.

Sometimes, I buy software (for example Blizzard's Starcraft II) that can install on both Mac and Windows using the same CD. Am I right in assuming these types of cross-platform software have both the mac AND windows binaries contained on that CD? Or is there some way to make the binaries hybrid?

Share this post


Link to post
Share on other sites
Im not sure how they do it in that case specifically but machine code is specific to the type of CPU, not the operating system.

For instance, you could make a binary that "ran" on windows linux and macintosh.

However, it would only be able to do really really really really basic stuff (like maybe not even anything useful... no input from the user, not output to the screen, no file i/o).

Anything beyond that is done through software interupts and dynamically linked libraries that are supplied by the operating system.

THIS is why in practice executables only work on mac or on linux or on windows.

However... it's possible (As far as i know) that since macintosh computers now use x86 processors, that you could theoretically make an executable that could detect which type of operating system you are using and then run the right program based on that.

Something else however, is that the format of file systems (hard drives, CDs, etc) on macintosh vs windows is different.

It *could* be that the disk is formatted in a special way such that windows sees what it expects, and mac sees what it expects etc and that both files live side by side on the disk.

Lastly, i know on windows you can put an "autorun" file on a disk that runs automatically when you put it in the drive. If mac has the same thing, but the "autorun" file is named something different, it would launch the windows installer on windows and the mac installer on mac - automagically.

One of these things would be my guess anyhow (:

This is a pretty advanced topic though and not likely something you'd ever have to deal with yourself, even if you were a professional game developer.

Share this post


Link to post
Share on other sites
I'm sure blizzard just includes mac and windows versions of all binaries on the disc, and installs the necessary files based on the running OS. Even though Mac and PC technically run the same machine code, the mac and windows version will be linked to different OS system libraries and will be compiled to a different executable format. Plus the code itself will be different for each platform in a few places, so that they can properly negotiate with the OS libraries.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
Even though Mac and PC technically run the same machine code
Careful there. While the CPU executes the same set of opcodes, Mac and Windows use different calling conventions/stack layout/etc., which changes how those opcodes are evaluated.

Software like WINE/Crossover (which allows Windows executables to run as is on a Mac) have to go through some interesting gymnastics to make it all work - and that even before all the API/OS differences.

Share this post


Link to post
Share on other sites

This topic is 2547 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this