Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » CDT clean in makefile not working
CDT clean in makefile not working [message #1796131] Fri, 05 October 2018 16:10 Go to next message
Eclipse UserFriend
I've just downloaded eclipse CDT and I'm writing programs in C++ using eclipse. My toolchain is MinGW GCC. Here's my makefile:

all: sunnymountains.exe

clean:
rm -f main.o sunnymountains.exe

sunnymountains.exe: main.o
g++ -g -o sunnymountains main.o

main.o:
g++ -c -g main.cppRightmove Kijiji Quizlet


sunnymountains.exe is the name of the application I'm writing. The issue is, if I edit main.cpp (the source code for sunnymountains) and then build the program, the old main.o and sunnymountains.exe files remain, and the application runs as if it had never been edited. Shouldn't my "clean" statement in the makefile take care of that? What do I have to write in the makefile to ensure that eclipse will clear out the old main.o and sunnymountains.exe files before building a new edit of the application?

[Updated on: Fri, 05 October 2018 20:25] by Moderator

Report message to a moderator

Re: CDT clean in makefile not working [message #1796144 is a reply to message #1796131] Sat, 06 October 2018 03:44 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
make determines the topological order of the targets.
The makefile should be written such that
1) The exe will be rebuilt if any of the object files (*.o) have changed.
2) The object files will be rebuilt if any of the source (*.cpp *.c) has changed.
Where changed here means newer than the target output.


In the makefile you have presented there are no dependendes for target main.o .
It will be built once then never again as long as it exists.
Is the makefile given here accurate?

The line starting main.o: should have the dependencies listed after the ':'
Much like sunnymountains.exe: main.o is saying build sunnymountains.exe if main.o changes

At a mimmum the line should read
main.o: main.cpp
if the things that follow it on the compile command can change then
main.o: main.cpp Rightmove Kijiji Quizlet

The clean target is used to remove files built during the make process.
It's meant to be run manually.
You execute it with: make clean
Since a file named "clean" is never built,
it will execute the recipe for clean every time for make clean


Learn more about make here:
Manual: https://www.gnu.org/software/make/manual/
Tutorial: https://opensourceforu.com/2012/06/gnu-make-in-detail-for-beginners/

The tutorial link above is the first I stumbled across.
I'm not necessarily endorsing it.
There are a number of tutorials on make.
Google gnu make tutorial for them.

This is going off-topic for this forum which is about Eclipse CDT issues.
You should direct specific questions about the tools being used and how to use them elsewhere.
stackoverflow.com for instance.

[Updated on: Sat, 06 October 2018 04:22]

Report message to a moderator

Previous Topic:Eclipse trace support for MTB in Cortex-m0+
Next Topic:How can we build notepad++ by use of Eclipse c/c++
Goto Forum:
  


Current Time: Fri Apr 26 19:39:37 GMT 2024

Powered by FUDForum. Page generated in 0.02736 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top