I want to write makefile to compile my C++ codes.

The tree of my files is this:

. ├── include │   └── Sort.h ├── lib │   └── Sort.cpp └── src ├── main.cpp ├── makefile └── obj 

And this is my makefile:

cc=g++ CFLAGS= -c -w .PHONY: all clean all: main main: main.o Sort.o $(cc) main.o Sort.o -o Sort -l m Sort.o: Sort.cpp ../lib $(cc) $(CFLAGS) main.cpp main.o: main.cpp ../include/Sort.h $(cc) $(CFLAGS) main.cpp clean: rm *.o main 

But I give this error after run make in terminal:

g++ -c -w main.cpp main.cpp:1:10: fatal error: Sort.h: No such file or directory 1 | #include <Sort.h> | ^~~~~~~~ compilation terminated. make: *** [makefile:16: main.o] Error 1 

Can you help me to edit my makefile?

0

1 Answer

Thanks for @steeldriver comment.

This is the right makefile:

cc=g++ CFLAGS= -c -w -I../include .PHONY: all clean all: main main: main.o Sort.o $(cc) main.o Sort.o -o Sort -l m Sort.o: ../lib/Sort.cpp ../include/Sort.h $(cc) $(CFLAGS) ../lib/Sort.cpp main.o: main.cpp ../include/Sort.h Sort.o $(cc) $(CFLAGS) main.cpp clean: rm *.o main 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy