g++ -c -o main.o main.cpp
I don't understand why it's not listing my flags in the output. Also, I know for a fact that it is ignoring -std=c++11
flag as it complains about non-static constant member, and it shouldn't with that flag enabled.
Edit0: Notation change
–
–
–
–
Your .o:
rule is not being selected, change it to .cpp.o:
instead.
By default (from the GNU make
doco):
n.o
is made automatically from n.cc
, n.cpp
, or n.C
with a recipe of the form '$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c'
The reason why your rule is not working in the first case is that a single-suffix implicit rule is supposed to be the source type rather than the target type. Hence the rule would be .cpp:
(again, from the make
doco):
A double-suffix rule is defined by a pair of suffixes: the target suffix and the source suffix. It matches any file whose name ends with the target suffix. The corresponding implicit prerequisite is made by replacing the target suffix with the source suffix in the file name. A two-suffix rule whose target and source suffixes are '.o'
and '.c'
is equivalent to the pattern rule '%.o : %.c'
.
A single-suffix rule is defined by a single suffix, which is the source suffix. It matches any file name, and the corresponding implicit prerequisite name is made by appending the source suffix. A single-suffix rule whose source suffix is '.c'
is equivalent to the pattern rule '% : %.c'
.
However, read that last sentence carefully. The .cpp:
rule is only effective if you want to turn XYZZY.cpp
into XYZZY
. Since your target is of the form XYZZY.o
, it won't be used.
Of course, the other alternative is to not touch the default rules at all, and instead just modify the variables they use:
CXX = g++
CPPFLAGS = -Wall -std=c++11 -O2
LD_FLAGS =
SOURCES = main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXE = HolidayLights.out
all: $(SOURCES) $(EXE)
$(EXE): $(OBJECTS)
$(CXX) $(LD_FLAGS) $(OBJECTS) -o $@
And, if you want to use implicit rules, you should really use the preferred form, which is the newer pattern rules. They're a lot more powerful than the suffix ones.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.