954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MakeFile creates executables on Windows '.exe' problem

Hey,

I have a problem that I'm not sure if its from running on windows or not.

Lets say I have the following MakeFile for compiling and creating the executable of 'target.c':

FLAGS = -Wall -g

all : target

target : target.o
           gcc ${FLAGS} -o $@ $^

target.o : target.c target.h
           gcc ${FLAGS} -c $^

clean :
           rm *.o target


Everything compiles just fine and all seems good with no errors.
Just when I try calling "make clean", it gives me this error:
rm: cannot remove `target': No such file or directory

so I navigated into the working directory that contains the files using cygwin, and saw that my executable was actually called 'target.exe', so I had to change the 'clean' function in my MakeFile into:

rm *.o target.exe

Which worked with no problems, but since I will need this to work on a Linux system as well, I'm not sure if changing to target.exe will also run on Linux with no problems.

Any advice on how to find a solution for this problem?

Thank you for your help.

blackrobe
Junior Poster in Training
52 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

change "rm *.o target.exe " to "rm *.o target.exe target"

kaoni317
Newbie Poster
6 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

or maybe rm *.o target*.*

[edit]:icon_eek: ^^^ That will also delete the source code![/edit]

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Do as kaoni317 suggests, but specify the -f flag.
rm -f *.o target.exe target

This will stop make from terminating just because one of the files don't exist.

IsharaComix
Junior Poster in Training
97 posts since Feb 2010
Reputation Points: 95
Solved Threads: 23
 

how about something like

if exist target rm -f target
if exist target.exe rm -f target.exe
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You