Makefile giving an error when compiling C++ object code and executables
I am trying to get a makefile to compile some object code and executables. But every time I get a warning and error saying
1 2 3 4 5 6 7
|
g++ -std=c++11 -Wall -Wextra -c -I item.h test.cpp
cc1plus: warning: item.h: not a directory [enabled by default]
test.cpp:10:21: fatal error: item.h: No such file or directory
#include <item.h>
^
compilation terminated.
make: *** [test.o] Error 1
|
The files I have are item.h, test.cpp, item.cpp. The only files I can change are the item.h and item.cpp not the test.cpp.
This is my makefile:
1 2 3 4
|
test.x: test.o
g++ -std=c++11 -Wall -Wextra -o test.o
test.o: test.cpp item.h
g++ -std=c++11 -Wall -Wextra -c -I item.h test.cpp
|
The test.cpp has the item.h in an include statement which cannot be altered.
#include <item.h>
I am not sure what's wrong, can somebody help?
You have to tell gcc that the currect directory is a library directory. You do that with:
[EDIT]
I've revised your makefile for you.
1 2 3 4 5 6 7 8 9
|
PROG_CXX = test
SRCS = test.cpp item.cpp
CXXFLAGS = -std=c++11 -Wall -Wextra -I .
all: $(PROG_CXX)
$(PROG_CXX): $(SRCS:.cpp=.o)
$(LINK.cc) -o $@ $^ $(LDFLAGS)
|
Last edited on
Thank you!, I at first didn't implement the dot beside I
but now I understand why it's needed.
Topic archived. No new replies allowed.