Makefile missing include path Although the path exists and defined

i have make file which i try to make them generic
but it keeps to compline it missing include directory
this is the makefile :

 CXX=g++
    CPPFAGS= -Wall -O0 -g -std=c++14
    INCLUDES = -I/home/vagrant/libuv/include -Isrc
    LIBS_DIRS = -L/home/vagrant/libuv/build
    LDFLAGS= -lssl -lcrypto
    LIB_STATIC = -Wl,--no-as-needed -Bstatic -luv_a -ldl -lpthread
    SOURCE = $(wildcard echo.cpp) \
             $(wildcard src/*.cpp)
    OBJ = $(SOURCE:.cpp=.o)
    DEP = $(OBJ:.o=.d)
    TARGET = myproj
    
    
    $(TARGET) : $(OBJ)
            $(CXX) $(CPPFLAGS) $(INCLUDES) -o $@ $^ $(LIBS_DIRS) $(LDFLAGS) $(LIB_STATIC)
    
    all: $(TARGET)
    
    clean:
            rm -f $(OBJ) $(TARGET)
    cleandep:
            rm -f $(DEP)
    
    .PHONY:all clean cleandep

when i make : make -n :

 

       make -n
    g++    -c -o echo.o echo.cpp
    g++    -c -o src/base64.o src/base64.cpp
    g++    -c -o src/Server.o src/Server.cpp
    g++    -c -o src/sha1.o src/sha1.cpp
    g++    -c -o src/Client.o src/Client.cpp
    g++  -I/home/vagrant/libuv/include -Isrc -o myproj echo.o src/base64.o src/Server.o src/sha1.o src/Client.o -L/home/vagrant/libuv/build -lssl -lcrypto  -Wl,--no-as-needed -Bstatic -luv_a -ldl -lpthread

when i invoke make , im getting this error:

     make
    g++    -c -o echo.o echo.cpp
    In file included from src/Server.h:9:0,
                     from echo.cpp:1:
    src/Client.h:6:10: fatal error: uv.h: No such file or directory
     #include <uv.h>
              ^~~~~~
    compilation terminated.
    make: *** [echo.o] Error 1

but the uv do exist in : /home/vagrant/libuv/include

Please list the directory as follow;

ls -l /home/vagrant/libuv/include

and post back the results (in code tags). See link in prior post if you forgot how to use code tags.

Hi
strange path /home/vagrant/libuv/include
vagrant is your username?

ls -l /home/vagrant/libuv/include
total 64
drwxrwxr-x. 2 vagrant vagrant   251 Dec 23 07:23 uv
-rw-rw-r--. 1 vagrant vagrant 64006 Dec 23 07:23 uv.h

What happens if you change:

g++    -c -o echo.o echo.cpp

to this:

g++  -I/home/vagrant/libuv/include  -c -o echo.o echo.cpp

?

1 Like

You collect object files without connecting the path to the header
You need to explicitly write -I/home/vagrant/libuv/include for a compilation of these objects
thanks @Neo
I deal with the task for a long time and did not reload the page

add the following lines

%.o: %.c 
        $(CXX) $(INCLUDES) -c $^ -o $@

You have several replies and I don't kow if your problem is solved but I'll mention that includes in <> are supposed to be for files in system directories i.e. /usr/include

Files in other directories should be referenced

#include "uv.h"

It's not been my experience that this causes compilation failures though.

-Greg.

1 Like
Summary

I made the following mistakes.

...
CFLAGS = -Wall -Wextra -O0 -g -Iinclude
OBJ = $(SRC: .c = .o) #There should be no spaces
...
.c.o: #no such files, the line did not work
        gcc $(CRLAGS) -c $< #typo in variable name
...

But thanks to this design in previous strings

vpath %.h include

It turned out that compilation was carried out by default line but header files were included though.
I fixed errors and reduced Makefile by 2 lines