How can I create a .exe file using C++ source code? I want to be able to write a program and simply have a double-clickable icon on the desktop to run it. Any help would be appreciated.
If you are using an IDE, like Borland's CodeGear, or Microsoft Visual Studio, or Dev-C++, or Code::Blocks, or Eclipse, etc, then you start a new project, type in your source, save it to the directory of your choice, and click the compile button, which will produce an executable in one of the following places:
- the same directory as the sources
- a debug directory
- a release directory (choice of debug or release depends on the options you have enabled)
If you are using a command-line compiler, like the GCC, use your favorite plain-text editor to create an ASCII-text source file and save it in the directory of your choice. Then change to that directory at the command-line and invoke your compiler. For example, with the GCC, it might look something like
g++ -Wall -pedantic a.cpp
(where a.cpp is the name of your source file). The executable will be found in the same directory. On Win32, it will be a.exe. On *nix, it will be a.out.
In Dev-C++ (at least) you can run a single-file program without making a project, which is very nice for experimenting with language features or running programs posted by people on this site. It also starts up quickly. However, Dev-C++ is otherwise not recommended since it is no longer in development. So it shouldn't be the only IDE you have.
I am using the netbeans IDE and when I compile I do find what I believe to be a binary executable, such as xxxxx.o but when I double click on it it simply opens in a text file with garbage text. I cannot find any .exe files.
I'm not familiar with net beans, but this is only half compiled. A project may use multiple cpp files each of which can be compiled separately into .o files. Then the .o files must be linked to create the exe.
It's a short extra step for small programs, but can save a lot of time in large projects since it allows the developer to only recompile the code that was changed.
You need to build the project, not just compile the file. Otherwise you're missing the linker step and therefore don't have an exe, only an object file.
I'm not sure about other compilers but on Dev C++ (which I use) you simply click "Compile" and it links it aswell. I've heard of all of those that Duoas listed, but never "Netbeans". I'm not sure if it's any good, but Dev C++ is definately very user friendly. Apparently so is MS VC++ however I don't like it because the GUI is very crowded, and looks a little "too flashy", as though they were more concerned with the GUI than the program. I also don't think it's very good for console projects.
Once you have compiled into .o or .obj (I think Borland CBuilder 6 used those, I can't remember), try and find somewhere where it says "Build" as Hammurabi suggested.
Whenever you compile through an IDE, it builds it for you. When you compile through a command prompt, by default we use compound commands to compile and build it or the commands from the compiler do it for us. I can't picture this being the problem. Usually, you may be able to make the seperate libraries (xxx.o files) but they may not be able to link together or the compiler may have errored out on a later file which I believe is the problem.
Netbeans if I remember uses GCC through the Cygwin port and is compatible with other compilers to an extent but not tested. It's IDE is complex and useful but it's not meant for small projects. It's meant for large and hard to control projects. Though it can be used for smaller projects, it's simply inconvenient.
Dev-C++ isn't an IDE you should start out on or should ever use. It's out of date which means bugs, glitches, features, and so on will never be fixed or added. Eventually the GCC compiler it works with may not hold up to the features of the current C++ standard, and as a result you would have to change anyways. You might as well develop a habit of using another IDE.
You can use the OS to find the executable. From the command prompt in Windows, change to the base directory of your program and search using
dir /s *.exe