943,779 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 8125
  • C++ RSS
Oct 4th, 2008
0

Compiling on cmd...

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

In linux I do

C++ Syntax (Toggle Plain Text)
  1. g++ filename.cpp -o filename

and run it using
C++ Syntax (Toggle Plain Text)
  1. ./filename

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

Quote ...
'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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sanchyvil is offline Offline
12 posts
since Jun 2008
Oct 4th, 2008
0

Re: Compiling on cmd...

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

C++ Syntax (Toggle Plain Text)
  1. 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

C++ Syntax (Toggle Plain Text)
  1. start C:\file.exe
Last edited by Freaky_Chris; Oct 4th, 2008 at 1:25 pm.
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Oct 4th, 2008
0

Re: Compiling on cmd...

Your Windows installation does not know where is the g++ executable. See
https://users.cs.jmu.edu/bernstdh/we..._mingw-faq.php
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Oct 4th, 2008
0

Re: Compiling on cmd...

You need to add the bin directory of MinGW to your PATH environment variable.
Reputation Points: 79
Solved Threads: 6
Posting Whiz in Training
TheBeast32 is offline Offline
236 posts
since Dec 2007
Oct 5th, 2008
0

Re: Compiling on cmd...

tnx for the help guyz!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sanchyvil is offline Offline
12 posts
since Jun 2008
Oct 5th, 2008
0

Re: Compiling on cmd...

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

C++ Syntax (Toggle Plain Text)
  1. 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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sanchyvil is offline Offline
12 posts
since Jun 2008
Oct 5th, 2008
0

Re: Compiling on cmd...

Click to Expand / Collapse  Quote originally posted by sanchyvil ...
I still have a problem... everytime i close cmd i always need to type

C++ Syntax (Toggle Plain Text)
  1. 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
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Oct 5th, 2008
0

Re: Compiling on cmd...

tnx for the help chris,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sanchyvil is offline Offline
12 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Matrix
Next Thread in C++ Forum Timeline: C++ vectors problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC