72629

Foreach Loop Not Working in Makefile: “The system cannot find the file specified”

Question:

I have a Makefile of the following content:

NUMBERS = 1 2 3 4 lib: $(foreach var,$(NUMBERS),./a.out $(var);)

And this is the command that I run ( in the same directory as the Makefile)

make -f Makefile

But I got an error message saying that "The system cannot find the file specified".

Following the suggestion of <a href="https://stackoverflow.com/questions/2018955/for-loop-not-working-in-makefile-the-system-cannot-find-the-file-specified/2019016#2019016" rel="nofollow">one of the answers</a>, I created the following file inside the same directory as the Makefile:

a.out 1.out 2.out 3.out 4.out

Now the error becomes:

<blockquote>

./a.out 1; ./a.out 2; ./a.out 3; ./a.out 4; make (e=-1): Error -1 make: *** [lib] Error -1

</blockquote>

<strong>Note: I am running on Windows XP platform</strong>

Answer1:

The purpose of make is to create (and update) target files that depends on source files by running commands.

Here, the problem is with the command that is run. You are trying to run (through make) the command a.out but it does not exist, or is not an executable command. Try to replace a.out in your makefile by the actual executable command you want to run.

Answer2:

It seems to me that the error comes because the file <b>a.out</b> cannot be located and not because the makefile could not be found.

Also if the name of your makefile is "Makefile" just invoking "make" is enough (without using -f option) as make by default would look for a file by names: GNUmakefile, makefile, and Makefile in that order.

Answer3:

Just what are you trying to do?

It seems to me that a plain script would be better suited rather than using make.

Answer4:

On Windows/DOS, use && instead of ; to join multiple commands on one line. You have to manually include a final command or the trailing && will throw a syntax error. Try something like:

NUMBERS = 1 2 3 4 lib: $(foreach var,$(NUMBERS),.\a.out $(var) && ) echo.

Recommend

  • Replicate elements from an array into a different array in Matlab
  • Get overall hours from two time picker
  • creating html with perl
  • What exaclty happens when a you call a constructor(new Class),do instance initializer blocks runs fi
  • Delete all blocks except specified ones in simulink model
  • How to trace the surface area as well as smoothen a specific region in an image using MATLAB
  • How can I use an array slice to access several elements of an array simultaneously?
  • Where i Can find text file created by servlet in Eclipse
  • writing to OutputStream having capacity restriction
  • Is there an more ideomatic way to split a stream by some predicate?
  • overhead of reserving address space using mmap
  • Xcode 6: Set Preprocessor Macros per architecture
  • Angular/Ionic 2 - what is a provider and what does `static get parameters()` do?
  • Xamarin Forms PopAsync crash
  • Trouble downloading file from browser on Android
  • Xamarin forms toggle button default color on IOS
  • Kinect API written solely in Java without native functions?
  • PHP: Very simple Encode/Decode string
  • How do I recognize a line break with a switch case that evaluates a char in Java?
  • On which thread JavaFX change listeners are executed ?
  • Consuming a web service with the Netbeans Platform
  • How to use Windows Media Foundation with UWP without a topology
  • how to set variables in a php include file?
  • Not able to aggregate on nested fields in elasticsearch
  • What's the purpose of QString?
  • x64 applications using gdi+: what are the consequences on performance?
  • How to define and use opencv mat of user type
  • Extracting HTML between tags
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Incrementing object id automatically JS constructor (static method and variable)
  • vba code to select only visible cells in specific column except heading
  • How can I use Kendo UI with Razor?
  • Free memory of cv::Mat loaded using FileStorage API
  • Hits per day in Google Big Query
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • Why joiner is not used after Sequence generator or Update statergy
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • unknown Exception android
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass