• 0

stupid question


Question

I am wondering if anyone here can help me. I have Visual Studio 08 but I prefer to use the MinGW compiler for small practice applications. The way I have been doing this is primitive so far: I open cmd.exe, cd to the place where I keep my source files, then type in "C:\Program Files\MinGW\bin\c++.exe" followed by the name of the source file and "-o " with a name after.

This is a hassle, and I want to know if there is a way to accomplish this using a batch file, BUT I want it to ask for the name of the source file and the name of the final executable, so that I don't have to manually edit the batch file each time I want to use it. Is this even possible?

A made a simple one that goes as follows:

cd c:\users\Brian\Documents\Programming
"c:\Program Files\MinGW\bin\c++.exe" hello.cpp -o hello

It does indeed compile it, but I don't want to have to edit the batch file every time I want to compile a new source. The hello.cpp are just examples.

edit:just noticed the cmd.exe part is unnecessary and didn't do anything anyway due to the typo!

Anyone?

Edited by Pompeius
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Why not just add 'c:\path\to\mingw\bin' to your system path?

Then you just have to call 'gcc/c++' from the command line (it'll work in any directory and you wouldn't have to call the full path anymore) so you'd basically wouldn't need a batch file anymore.

Link to comment
Share on other sites

  • 0

Since I am not to good at Cmd Promt, I wrote a VBS script that should do what you want.

I have only tested this so it does not have any Runtime errors.

Save As Compile.vbs

Dim A1, A2
Dim Z1 :Z1 = "To Exit this and do nothing type Exit"
'-> Loop 1 Until User Adds Input
	Do While A1 = ""
	 A1 = InputBox("Type in the Name of the source file to process" & vbCrLf & Z1)
	 If LCase(A1) = Lcase("Exit") Then WScript.Quit
	Loop
'-> Loop 2 Until User Adds Input
	Do While A2 = ""
	 A2 = InputBox("Type in a Name for this applcation" & vbCrLf & Z1)
	 If LCase(A2) = Lcase("Exit") Then WScript.Quit
	Loop
'-> Check To Make Sure A1 And A2 Have At Least One Character
	If Len(A1) > 1 And Len(A2) > 1 Then
	' WScript.Echo A1 & " " & A2
	 CreateObject("Wscript.Shell").Run _
	 ("Cmd.exe /K " & Chr(34) & "c:\Program Files\MinGW\bin\c++.exe" & Chr(34) & A1 & " -o " & A2),1,True 
	End If
Link to comment
Share on other sites

  • 0

A script that does what you want looks like this:

@echo off
cd c:\users\Brian\Documents\Programming
"c:\Program Files\MinGW\bin\c++.exe" %1 -o %2

Save it as compile.bat and run it as compile hello.cpp hello

I have to wonder though, if maybe a better solution would be to create a custom command line environment that has the proper path set so that you could just double-click it and then type in c++ hello.cpp -o hello

To do that you could put this in setvars.bat:

@set PATH=C:\Program Files\MinGW\bin;%PATH%

Then right-click on the desktop and select new shortcut. When it asks for the location of the item, type:

%comspec% /k "C:\path\to\setvars.bat"

Click next and give it whatever name you want. You can then right-click on the new shortcut and set the "Start in" field to wherever you want it to start by default. You could also put that in setvars.bat.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.