0

I am trying to write a make file for the following program

MY file/folder structure is as follows

Folder/File structure
./demo/utilities.c
./demo/utilities.h
./demo/makefile
./include/GeographicLib/UTMUPS.h
./include/GeographicLib/Constant.h
./include/GeographicLib/xxxxxxx

in the file utilities.h

#include <GeographicLib/UTMUPS.h>

in the file UTMUPS.h

#include <GeographicLib/Constant.h>

in the makefile

# preprocessor
PREPROC_FLAGS += -DEIGEN_DONT_ALIGN_STATICALLY
INC_XTRA_DIR = ../include
CC=g++
CPPFLAGS= $(PREPROC_FLAGS)
CFLAGS=-O2 -g -Wall -W -I$(INC_XTRA_DIR)
CXXFLAGS=-O2 -g -Wall -W -fpic -std=c++11 

# short hand
OBJDIR=obj
Utilities_h = utilities.h GeographicLib/UTMUPS.hpp

utilities.o: utilities.c  $(Utilities_h) 
    $(CC) $(CPPFLAGS) $(CFLAGS)  -c $< -o $@

all: $(FINAL_TARGET)

$(FINAL_TARGET): $(OBJ)
    $(CC) -g -o $@ $^ $(LDFLAGS)
ifneq ($(wildcard ../databases/.),)
    cp $@ ../
endif

TargetList = $(FINAL_TARGET) 

clean:
    rm -f $(TargetList) *.o *~
    echo Clean done.

The question I want to ask is

  1. When I compile the following project, it say it can't find "#include 'GeographicLib/UTMUPS.h'". in the utilities.h. what should the naming be in this case. My thought is that by adding -I$(INC_XTRA_DIR), or ../include ... it should search for GeographicLib/UTMUPS.h
  2. what about the file that UTMUPS.h is dependent on(in this case Constant.h), what should be the addressing

Edit: I run make at the root directory... maybe that's the reason for the error.

THanks

user1538798
  • 1,075
  • 3
  • 17
  • 42
  • Does this answer your question? [How to define several include path in Makefile](https://stackoverflow.com/questions/4134764/how-to-define-several-include-path-in-makefile) – LPs Dec 12 '19 at 08:03
  • @LPs is there a difference if we use -I$(include_directories) instead – user1538798 Dec 12 '19 at 08:06
  • 2
    -I wants one path per option, include_directories are a concat of paths – LPs Dec 12 '19 at 08:15
  • 3
    Where do you run `make`? *How* do you run `make`? Please copy-paste the full command *and* the full output and add it to the question. And add the output of `pwd` before you run `make` so we can see your current directory. – Some programmer dude Dec 12 '19 at 08:20
  • 2
    If you run `make` at the root directory and add `../include`, `make` will search the `include` folder at parent directory. Try changing to `./include`. – kurtfu Dec 12 '19 at 08:31
  • 1
    You might like to read about the `VPATH` in `make`. Please note that `make` and your compiler are completely separated beasts. What one of them knows and uses is not automatically known by the other. – the busybee Dec 13 '19 at 06:49

0 Answers0