Include header file in different directory in c++

前端 未结 3 1269
谎友^
谎友^ 2021-01-17 18:37

I\'ve been learning c++ and encountered the following question: I have a directory structure like:

 - current directory

  - Makefile

  - include

     - he         


        
3条回答
  •  庸人自扰
    2021-01-17 18:47

    You can either add a -I option to the command line to tell the compiler to look there for header files. If you have header files in include/ directory, then this command should work for you.

    gcc -Iinclude/
    

    Since, you are using makefile, you can include this option in CFLAGS macro in your makefile.

    CFLAGS = -Iinclude/ -c -Wall
    

    OR

    You can include header files using #include "../include/header.h".

提交回复
热议问题