Hi I want to know how to compile c++ codes using the command prompt in windows.

In linux I do

g++ filename.cpp -o filename

and run it using

./filename

but for windows when I try this procedure in compiling i got an error message

'g++' is not recognized as an internal or external command,operable program or batch file

I know that the IDE already has a compile button...

please help...

I trust you have installed all of the required libraries etc

And set up all global varialbles.

once all is set up i believe this should work

g++.exe "C:\file.cpp" -o "C:\File.cpp" -I"Include directory"  -I"another include directory and so on"  -L"libraries"

and to run it

start C:\file.exe

You need to add the bin directory of MinGW to your PATH environment variable.

tnx for the help guyz!

I still have a problem... everytime i close cmd i always need to type

set PATH=%PATH;bin location

before i can use the g++ command.

Is there a way that I can directly use the g++ command after launching cmd?

I still have a problem... everytime i close cmd i always need to type

set PATH=%PATH;bin location

before i can use the g++ command.

Is there a way that I can directly use the g++ command after launching cmd?

Yes follow these steps sorry if you already know, i'm going to assume your on XP


1) Right click my computer
2) Select Properties
3) Advanced Tab
5) Environment Variables
6) Under system variables find "Path"
7) Click edit and append with a semicolon separator the new location

And your done, hope that helps

Chris

tnx for the help chris,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.