James Bond
James Bond

Reputation: 7913

why there is no compilation flags in this makefile?

i was reading this post on makefile. I found that I cannot find where are the compiler and compilation flags defined. Normally they are defined as CXX and CFLAGS

i copied this makefile for my own testing project:

BUILD_DIR := /home/ubuntu/workspace/common/bin

vpath %.cpp /home/ubuntu/workspace/common/src

SRCS := basic_types.cpp

OBJS := ${SRCS:%.cpp=${BUILD_DIR}/%.o}  
foo: ${OBJS}
        @echo Linking $@ using $?
        @touch $@

${BUILD_DIR}/%.o: %.cpp      # <-- I had thought there will be some more specific 'rules' here
        @mkdir -p $(dir $@)
        @echo Compiling $< ...
        @touch $@

${SRCS}:
        @echo Creating $@
        @mkdir -p $(dir $@)
        @touch $@

.PHONY: clean

it compiles well, but i still cannot find any where to specify the complier. Is Make intelligently select the compiler (g++) for me based on surffix?

could anyone take a look and enlight me a bit? thanks a lot!

the original post on makefile

Upvotes: 0

Views: 69

Answers (1)

Beta
Beta

Reputation: 99144

Your question is a little unclear, since you've written a rule for object files that doesn't actually compile anything, but you say that "it compiles well".

There is an implicit rule that acts like this:

%.o: %.cpp
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@

You can specify the compiler with a line like this:

CXX = g++

But g++ is already the default value of CXX.

Upvotes: 1

Related Questions