-1

I like using both Linux and Windows for my C and C++ coding and I prefer using the command line to compile my programs. I can run make on Linux, which is fine. But on Windows, now that I'm working with classes and have to compile multiple files, I find it a chore to type in several g++ commands to compile the class and main object files.

I was wondering if there's a way to get a CMD batch file or PowerShell script to just execute the commands one after the other?

Something like this:

g++ -c Area.cpp -o Area.o
g++ -c Convert.cpp -o Convert.o
g++ -c Calculate.cpp -o Calculate.o
g++ -c multi_menu_functions.cpp -o multi_menu_functions.o
g++ -c main.cpp -o main.o
g++ -Wall main.o Area.o Calculate.o Convert.o multi_menu_functions.o -o main

...Something dead simple and easy.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Quinn
  • 1
  • The commentary on the tag you used says "A batch file is a text file containing a series of commands that are executed by the command interpreter on MS-DOS, IBM OS/2, or Microsoft Windows systems." But more usual to use a formal make file. – Weather Vane Dec 04 '16 at 23:19
  • look here for options for continuing to use "make": http://stackoverflow.com/questions/16755641/make-command-for-windows-possible-options – TonyB Dec 04 '16 at 23:29
  • `g++ Area.cpp Convert.cpp Calculate.cpp multi_menu_functions.cpp main.cpp -std=c++11 -Wall -pedantic-errors -o main.exe`. Or just use `make`. There is a make distributed with g++, and there's Microsoft's `nmake`. Or use Microsoft's build system `msbuild`. Or Cmake. Or, just put all those commands you have in a batch file. I fail to see the problem. – Cheers and hth. - Alf Dec 04 '16 at 23:37

2 Answers2

0

Just write the commands in a file with extension .bat and you can just start that file. You can turn off outputting the commands while execution of the batch file by starting the file with the line @echo off.

Or better yet: Just get make for windows and use that one.

Bodo Thiesen
  • 2,476
  • 18
  • 32
  • I did put the commands in a .bat file, they won't run as is. Are there specific DOS keywords to execute the g++ commands? I know there are several make out there for windows, but I wanted to know if you can do it with a .bat or powershell script. – Quinn Dec 05 '16 at 00:33
0

I figured out the issue of why the g++ commands wouldn't work as is: somehow the laptop I was using didn't grant me the correct permissions. At a guess I tried the full path name for g++.exe and it worked. I reconfigured some things and now it works with the commands as listed.

On a side note; I did get gnumake and minGW make working as well. Since these can run my Linux makefiles I'll use these as well.

Quinn
  • 1