Reputation: 15010
I have the makefile given below. When I do make
I get the following error
cc -c -o timing.o timing.c
test_c.c:5:17: fatal error: test.h: No such file or directory
#include "test.h"
I have manually verfied that test.h
is present in ../include
path. I am not sure why this is not finding the header file.It would be great if someone could help.Also I would expect g++
instead of cc
# Makefile template for shared library
CXX = g++ # C++ compiler
CXXFLAGS = -fPIC -Wall -Wextra -O2 -g -I../include #CXX flags
LDFLAGS = -lboost_system -shared # linking flags
RM = rm -f # rm command
TARGET_LIB = libtest.a # target lib
C_SRCS := test_a.c test_b.c
CPP_SRCS := test_c.cpp test_d.cpp
OBJS := $(C_SRCS:.c=.o) $(CPP_SRCS:.cpp=.o)
.PHONY: all
all: ${TARGET_LIB}
$(TARGET_LIB): $(OBJS)
$(CXX) $(CXXFLAGS) ${LDFLAGS} -o $@ $^
.PHONY: clean
clean:
-${RM} ${TARGET_LIB} ${OBJS}
~
Upvotes: 0
Views: 2941
Reputation: 99172
You have not written a rule for building timing.o from timing.c, so Make uses the default rule it has for that.
But that rule uses CFLAGS
, not CXXFLAGS
. The CXXFLAGS
variable appears in the rule for building object files from C++ sources.
So modify CFLAGS
instead of CXXFLAGS
, and it should work.
Upvotes: 1