943,165 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 720
  • C RSS
Feb 23rd, 2010
0

MakeFile creates executables on Windows '.exe' problem

Expand Post »
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':

  1. FLAGS = -Wall -g
  2.  
  3. all : target
  4.  
  5. target : target.o
  6. gcc ${FLAGS} -o $@ $^
  7.  
  8. target.o : target.c target.h
  9. gcc ${FLAGS} -c $^
  10.  
  11. clean :
  12. 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:
  1. 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
blackrobe is offline Offline
52 posts
since Oct 2008
Feb 23rd, 2010
0
Re: MakeFile creates executables on Windows '.exe' problem
change "rm *.o target.exe " to "rm *.o target.exe target"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kaoni317 is offline Offline
6 posts
since Feb 2010
Feb 23rd, 2010
0
Re: MakeFile creates executables on Windows '.exe' problem
or maybe rm *.o target*.*
[edit] ^^^ That will also delete the source code![/edit]
Last edited by Ancient Dragon; Feb 23rd, 2010 at 8:25 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2281
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,938 posts
since Aug 2005
Feb 23rd, 2010
0
Re: MakeFile creates executables on Windows '.exe' problem
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.
Last edited by IsharaComix; Feb 23rd, 2010 at 11:14 pm.
Reputation Points: 95
Solved Threads: 23
Junior Poster in Training
IsharaComix is offline Offline
96 posts
since Feb 2010
Feb 23rd, 2010
0
Re: MakeFile creates executables on Windows '.exe' problem
how about something like
  1. if exist target rm -f target
  2. if exist target.exe rm -f target.exe
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2281
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,938 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Triangle
Next Thread in C Forum Timeline: can i define self-referential structure like this?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC