繁体   English   中英

如何使用 Makefile 从另一个目录包含 header 文件?

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

将此视为我的目录结构:

- 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> )使用Makefile (意味着 Header 文件路径可以包含在 Makefile 中)。 是否可以使用Makefile包含这些标题? 如果有人知道如何使用 Makefile 或任何建议在不更改目录结构的情况下执行此操作,请告诉我。

在您的 Makefile 中,通常会执行以下操作:

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

然后:

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

您可以根据需要拥有任意数量的 -I arguments。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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