Reputation: 575
I run make with this makefile on main.cpp
which does nothing.
CXX = g++
CXXFLAGS = -g -std=c++11 -stdlib=libc++ -Wall
SRCDIR = .
TARGET = tfm
SRCS = $(SRCDIR)/main.cpp
OBJS = $(SRCS:.cpp=.o)
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^
clean:
$(RM) $(TARGET) $(OBJS)
And, compile was done twice.
g++ -g -std=c++11 -stdlib=libc++ -Wall -c -o main.o main.cpp
g++ -g -std=c++11 -stdlib=libc++ -Wall -o tfm main.o
Why is this happening?
Upvotes: 0
Views: 378
Reputation: 72756
And, compile was done twice.
No, it wasn't. The first line shows the compilation of main.cpp
into main.o
(which gets triggered by a built-in make
rule for how to turn *.cpp
into *.o
).
The second shows the link step, linking main.o
with libraries to result in the executable tfm
.
In other words, everything is swimmingly beautiful.
Upvotes: 2
Reputation: 23871
Running make on the source code does not make much sense. You have to tell make what you want to generate. And you do not want to generate the source.
Complation is not done twice. The first line compiles the the second line links.
Upvotes: 0