Posted: Sun Mar 21, 2010 5:50 pm Post subject: RE:How do you run code in C++??
You'll be needing to get a compiler. One is included with at least some Linux distro. Macs have g++ included in their developer tools which come on the OS X installation disk. You'll have to download one for Windows. Don't ask me how to install it on Windows, I don't know. Once it's installed, single-file scripts can be executed by typing 'g++ <filename>' in the terminal. Dunno how this works on Windows, once again. Lager projects will require a makefile. If you've downloaded source code the makefile will prolly already be included, in which case type 'make <filename>' and if applicable, 'make install <filename>'. I don't know the specifics and of course I don't know how any of this works on Windows. There is a tutorial around here somewhere (a rather new one I believe, unless someone necro'd it to lead me to believe it was new) that you can check out that goes into specifics about makefiles.
DtY
Posted: Sun Mar 21, 2010 5:51 pm Post subject: RE:How do you run code in C++??
Generally, the process is something like this:
- Compiler: Each source file compiled into a machine dependent assembly language
- Assembler: Assembled into object files, which are nearly executables, but contain symbols so other objects can find resources (functions, classes, &c) in it.
- Linker: Objects are linked together along with runtime stuff that sets up the environment (which will then call your main()), this step produces an executable file (if you're on Windows, it's a .exe).
- Loader: The executable is loaded into memory, and launched by the operating system.
You really only need to be concerned with the compiler and linker, generally the assembler step is automatic, and the loader is invoked like for any other executable (double click on Windows, or ./executable on *nix).
If you're using an IDE, look for a button that says Build and Run, or something similar.
[edit] Insectoid's instructions are probably more what you were looking for
Insectoid
Posted: Sun Mar 21, 2010 5:54 pm Post subject: RE:How do you run code in C++??
Posted: Mon Mar 22, 2010 7:09 pm Post subject: Re: How do you run code in C++??
wow this is a lot of work just to get C++ started .........
BTW thanks for the help
Insectoid
Posted: Mon Mar 22, 2010 7:15 pm Post subject: RE:How do you run code in C++??
It's the same for most compiled languages (or at least, very similar). Interpreted languages require an interpreter installed, much in the same way. Install one and you can install 'em all.
Sponsor Sponsor
Kharybdis
Posted: Mon Mar 22, 2010 9:50 pm Post subject: Re: How do you run code in C++??
I would suggest starting with the dev c++ compiler (my bias is because it runs on usbs ).
If you're running windows, dev c++ or visual c++ is your best bet for a good compiler. Linux has its own compilers, like vi or nano, i think.
For dev c++, just include everything that you would in a program such as 'hello world', and run the button that says 'run and compile'. Kinda obvious, actually. If you have more than one file (eg. .cpp and .h files), you're going to have to make a project, associate all the files that you need with that project, and once again, compile and run the project.
A useful command to know right away is 'system("pause"). Put that right before your return statements, as it makes you enter a key before the program exits. Otherwise, you're going to have a dos-like prompt flash at you and close, which is annoying to say the least.
wtd
Posted: Tue Mar 23, 2010 12:19 pm Post subject: Re: RE:How do you run code in C++??
GCC is the GNU Compiler Collection. "gcc" and "g++" are both front-end programs to that collection. Given the correct arguments passed to it, "gcc" can be used for C or C++ (or any number of other languages) programs.
wtd
Posted: Tue Mar 23, 2010 12:21 pm Post subject: Re: How do you run code in C++??
Kharybdis @ Tue Mar 23, 2010 10:50 am wrote:
If you're running windows, dev c++ or visual c++ is your best bet for a good compiler. Linux has its own compilers, like vi or nano, i think.
Dev C++ and Visual C++ are both integrated development environments. This means that they usually bundle up a compiler, but also include a bunch of other crap to scare off novice programmers.
Vi and nano are both just text editors, and will not serve to compile C++ code.
wtd
Posted: Tue Mar 23, 2010 12:24 pm Post subject: RE:How do you run code in C++??
Given the level of knowledge I'm detecting in this thread, C++ is not a good language for you to be tackling right now. C++ is not a beginner language.
There are any number of other better choices.
USEC_OFFICER
Posted: Tue Mar 23, 2010 12:30 pm Post subject: RE:How do you run code in C++??
Like? Give a few examples for the guy, he can't read minds you know. (I'm not going to bring up the story.)
chrisbrown
Posted: Tue Mar 23, 2010 1:43 pm Post subject: RE:How do you run code in C++??
My two cents: Python, Ruby, or Scheme. None require any extraneous code to get a working program, so it is easy to get started immediately; however all are scalable to be useful for large projects as well (classes, abstraction, etc...), so there is no ceiling as to what you can learn.
Kharybdis
Posted: Tue Mar 23, 2010 1:56 pm Post subject: Re: How do you run code in C++??
wtd @ Tue Mar 23, 2010 12:21 pm wrote:
Kharybdis @ Tue Mar 23, 2010 10:50 am wrote:
If you're running windows, dev c++ or visual c++ is your best bet for a good compiler. Linux has its own compilers, like vi or nano, i think.
Dev C++ and Visual C++ are both integrated development environments. This means that they usually bundle up a compiler, but also include a bunch of other crap to scare off novice programmers.
Vi and nano are both just text editors, and will not serve to compile C++ code.
my bad. yah, they are text editors. in linux, i just make .cpp or .h files in vi or nano and then run them by using g++. You mention that the IDEs scare the novice programmers, but if you want to learn c++, they're still the best option.
I agree with you though that Python would be a better language to learn first because of its gradual learning curve and ease of use. t