I hava a just simple question. I made a just simple Makefile like this
OBJ = main.o Str.o Out.o
CC = g++
TAR = main
$(TAR):$(OBJ) Header.h
$(CC) -o $(TAR) $(OBJ)
clean:
rm -f $(OBJ) $(TAR)
I have just Str.cpp, Out.cpp, main.cpp in my current directory.
Even if I miss the process which converts source file into objectfile
(like g++ -c Str.cpp), it works well.
I'm curious why this Makefile works. Does it make objectfiles automatically??
Compiling C++ programs
n.o is made automatically from n.cc, n.cpp, or n.C with a recipe of the form ‘$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c’. We encourage you to use the suffix ‘.cc’ for C++ source files instead of ‘.C’.
The answer is yes, it creates object files in the same directory for each source file (and then links them all with your rule to final executable).
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