简体   繁体   中英

How can i include header files from another directory using Makefile?

Consider this as my directory structure:

- Main_Dir    
         - Dir1
         |      - Dir2
         |      |     - A.h
         |      |     - B.h
         |      - Dir3
         |            - C.c
         - Makefile

My requirement is that, i have to only use #include <Dir2/Ah> and #include <Dir2/Bh> in the C.c file to include those header files(but not #include <Dir1/Dir2/Ah> and #include <Dir1/Dir2/Bh> ) using Makefile (means that Header files Path can be included in Makefile). Is it Possible to include those headers like that using Makefile ? If anyone Knows on how to do it using Makefile or any suggestions to do it without changing the Directory structure Please let me know.

In your Makefile, it is common to do something like this:

CXXFLAGS += --std=c++17 -I..

and later:

foo.o: foo.cpp
     g++ ${CXXFLAGS} foo.cpp -o foo.o

You can have as many -I arguments as you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM