Reputation: 25
I wrote a very simple Makefile like this:
CXX = g++
CFLAG = -g -I../include
XNNLIB = ../src/cpuxnn.a
PROGS = testcpu
all: $(PROGS)
%: %.c $(XNNLIB)
(this is a tab here)$(CXX) $(CFLAG) -o $@ $^
and "make" starts g++ like this:
g++ testcpu.cpp -o testcpu
What happened to the CFLAG var???? and why the command is in such a mess order? I searched and researched but no answer. Please help!
Upvotes: 0
Views: 23
Reputation: 171253
You've written a pattern rule for .c
files, but make is finding a .cpp
file, so it compiles it using the built-in rules for compiling C++.
You need to change your pattern rule to use %.cpp
not %.c
It's conventional to use variables called CFLAGS
(for C) and CXXFLAGS
(for C++) not CFLAG
Upvotes: 3