0

I have very specific instructions:

I am to write a code in c++ that runs from the command line as follows:

make compile

make run file.txt alpha > output.txt

Currently, I know how to write a make file to run the compiled code...

run:
    ./my_program.exe

But how would I write a makefile such that the make file runs:

./my_program file.txt alpha

When I type:

make run file.txt alpha

??

Chris
  • 28,822
  • 27
  • 83
  • 158
  • 1
    Makefiles are not really designed for running programs. Why not just run the program? – Galik Mar 21 '17 at 23:15
  • @Galik not really sure why. I'm still in school...it is a turn in requirement for an assignment...is there a way I can hack it? – Chris Mar 21 '17 at 23:17
  • So you just want to pass variables into make? http://stackoverflow.com/questions/2826029/passing-additional-variables-from-command-line-to-make – Tuffwer Mar 21 '17 at 23:17
  • @Tuffwer the assignment specifies exactly the line in the question (don't see a backtick on the cellphone keyboard): make run input1 input2 – Chris Mar 21 '17 at 23:21
  • @Tuffwer since it'll be an auto grader, I'm thinking there isn't too much flexibility... – Chris Mar 21 '17 at 23:21
  • 1
    Will this work? http://stackoverflow.com/a/6273809/5220640 – Tuffwer Mar 21 '17 at 23:28
  • Will the grader actually vary those parameters? – Beta Mar 21 '17 at 23:30
  • @Tuffwer wow. that was a find (guess not, actually--105 upvotes). thank you though--worked; just had to change some stuff. you think I should leave this up, link that answer, and mark as duplicate? Or delete? – Chris Mar 21 '17 at 23:31
  • It is asking the same thing so a duplicate would fit. In terms of the solution really it's a bit of a hack. An alternative approach (which is where I think @Beta was going) is if you just have to have it run with that specific string you could have a run target that just hard codes those parameters, but without knowing for sure that seems to be a risk. – Tuffwer Mar 21 '17 at 23:35
  • @Tuffwer ah, ok. yeah, I think that I'm going to go with this for now, and talk to a TA next week. Thanks man. Looking for a book on make as we speak :) – Chris Mar 21 '17 at 23:37

0 Answers0