Computer Science Canada

Setting up a C++ compiler for Windows Command-Line

Author:  apomb [ Wed Nov 03, 2004 3:32 pm ]
Post subject: 

Well, im just trying to get a leg- up for next semester ... I am eventually going to learn it from school, but i have not had a good time figuring out C++ code. I really want to learn it, but i can wait for instruction on that language.

Author:  wtd [ Wed Nov 03, 2004 3:49 pm ]
Post subject: 

Feel free to ask any questions you have in C/C++ Help and I'll be happy to answer them if I can.

Author:  apomb [ Thu Nov 04, 2004 12:39 am ]
Post subject: 

well, when i compile and run the simple "hello world" program, nothing happens (wil only run a bunch of words in the bottom of the "output" area, but no "hello world")

im on Dev C++... what am i missing

Author:  wtd [ Thu Nov 04, 2004 12:41 am ]
Post subject: 

CompWiz333 wrote:
well, when i compile and run the simple "hello world" program, nothing happens (wil only run a bunch of words in the bottom of the "output" area, but no "hello world")

im on Dev C++... what am i missing


The IDE is getting in the way. You need a simpler setup.

Which OS are you running?

Author:  apomb [ Thu Nov 04, 2004 12:43 am ]
Post subject: 

i was going to post that with the other info, but im on "Me"... sadly

Author:  wtd [ Thu Nov 04, 2004 12:48 am ]
Post subject: 

CompWiz333 wrote:
i was going to post that with the other info, but im on "Me"... sadly


Do a search for "g++.exe" on your computer. Find the directory that that program lives in. Copy it.

This is from the Java setup page, slightly modified.

From the start menu, choose programs, accessories, system tools, and system information. This brings up a window titled "Microsoft Help and Support". From here, choose the tools menu, then select the system configuration utility. Click the environment tab, select PATH and press the edit button. Now add the location of g++.exe to your path as described in step b above. After you've added the location of g++.exe to your PATH, save the changes and reboot your machine when prompted.

Author:  apomb [ Thu Nov 04, 2004 12:56 am ]
Post subject: 

and this does ....

Author:  wtd [ Thu Nov 04, 2004 1:00 am ]
Post subject: 

Once you've done that, open a command prompt and type

code:
C:\> g++


You should be greeted by something like:

code:
g++: no input files


If you are, then congrats, you have a working C++ compiler you can use from the command-line.

Compiling a source file then is as simple as:

code:
C:\> g++ my_program.cpp -o my_program.exe


And running it is:

code:
C:\> my_program


Of course you have to cd to the directory where your source file is, first.

Author:  apomb [ Thu Nov 04, 2004 1:09 am ]
Post subject: 

it says "page cannot be displayed"! dammit, and the path is correct too, hmm
hey, now theres a black screen, but it only flashes for like a nano second, then i closes

Author:  wtd [ Thu Nov 04, 2004 1:11 am ]
Post subject: 

CompWiz333 wrote:
it says "page cannot be displayed"! dammit, and the path is correct too, hmm


How far are you getting? Where are you running into the problem?

Author:  apomb [ Thu Nov 04, 2004 1:13 am ]
Post subject: 

where do i type it, in an internet explorer console or DOS?

Author:  wtd [ Thu Nov 04, 2004 1:14 am ]
Post subject: 

CompWiz333 wrote:
where do i type it, in an internet explorer console or DOS?


DOS.

Author:  apomb [ Thu Nov 04, 2004 1:19 am ]
Post subject: 

alright, got that, now it has already
code:
C:\WINDOWS>
and then "bad command or file name"

ill try rebooting again ...

Author:  wtd [ Thu Nov 04, 2004 1:22 am ]
Post subject: 

Not sure since I'm using 2000 Pro, but try typing "path" at the prompt and seeing if the string you see includes the path to g++.exe.

Note: you shouldn't include the "g++.exe" in that path. Just the directory path.

Author:  apomb [ Thu Nov 04, 2004 1:31 am ]
Post subject: 

heres what is on screen right now:

code:
Bad command or file name
C:\WINDOWS>path
PATH=C:\WINDOWS\COMMAND\g++.exe


its there, now what? ...

Author:  wtd [ Thu Nov 04, 2004 1:36 am ]
Post subject: 

CompWiz333 wrote:
heres what is on screen right now:

code:
Bad command or file name
C:\WINDOWS>path
PATH=C:\WINDOWS\COMMAND\g++.exe


its there, now what? ...


Now, create a simple C++ program called hello.cpp.

code:
#include <iostream>

int main()
{
   std::cout << "Hello, world!" << std::endl;
   return 0;
}


And compile it:

code:
C:\Directory\your\program\is\in> g++ hello.cpp -o hello.exe


Then run it with:

code:
C:\Directory\your\program\is\in> hello

Author:  apomb [ Thu Nov 04, 2004 2:41 am ]
Post subject: 

oh man ... this is pissing me off, nothing is working, every time i push enter, it says "bad command or file name" and goes right back to

code:
C:\WINDOWS>


not just plain

code:
C:\>


WTF!

Author:  wtd [ Thu Nov 04, 2004 3:43 am ]
Post subject: 

CompWiz333 wrote:
oh man ... this is pissing me off, nothing is working, every time i push enter, it says "bad command or file name" and goes right back to

code:
C:\WINDOWS>


not just plain

code:
C:\>


WTF!


You're in the C:\Windows directory. To change directories use:

code:
C:\whatever> cd target_directory


If that directory is on a different drive...
code:
C:\whatever> f:


To change to the F drive, as an example.


: