I am taking a C++ course in college and they want us to manually type in all of the test files... I know, however, that there is a way to do it with out, which is how I ended up with the current(http://pastebin.com/6d9UtKM4) makefile. My question is, why is this makefile automatically removing all the .o files it uses for compiling when it is done? It's not killing me, but I would like to preserve the .o files. I have pasted the makefile here(http://pastebin.com/6d9UtKM4). I have also pasted the current result of running "make tests" here(http://pastebin.com/h3Ny3dib). (Note the part at the bottom of that page that removes all the .o files automatically.)
I would also like to be able to make it generate it like this:
In other words, I want it to compile everything, then run everything. I hope this isn't too much to ask!
Edit: Additional Information: (This is the code that does "make tests")
tests: assembler.o string.o $(test_output) $(test_stringOutput)
@echo '--- Testing complete ---'
$(testDir)%: $(compileDir)%.o string.o
g++ -o $@ $< $(compileDir)string.o $(compileDir)assembler.o
$@
@echo ''
$(compileDir)%.o: $(testSourceDir)%.cpp
g++ -c -Wall -o $@ $<
$(compileDir)%.o: $(testStringSrc)%.cpp
g++ -c -Wall -o $@ $<
EDIT: -----------------------------------------
Resolved via comments:
Adding this line fixed it: .PRECIOUS $(compileDir)%.o
.o denote "object-files", these are files compiled from source but not yet linked into an executable or a library. In your make-file, i.e. main.o : main.cpp. says that main.o will be created from main.
The Cleanup Rule clean: rm *.o prog3 This is an optional rule. It allows you to type 'make clean' at the command line to get rid of your object and executable files. Sometimes the compiler will link or compile files incorrectly and the only way to get a fresh start is to remove all the object and executable files.
An object file ( .o ) is not executable. You want to be running ./demo_fully_homomorphic (e.g. the file without extension). Make sure you have execute permissions ( chmod a+x demo_fully_homomorphic ).
The ".o" files are likely intermediate files from which the actual executable program should have been created. The ". d" files are likely internal state used by the makefile, only important if you are making changes to the source code and then rebuilding "incrementally".
Yes, you can remove it. BUT, if you program consists of multiple files and you change one of them, lack of .o s would make CB recompile the entire program (once) instead of just the changed file.
You might add
.PRECIOUS: %.o
which should be implicit, but perhaps you've got a weird setup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With