【发布时间】:2021-03-05 03:40:33
【问题描述】:
下面是(示例)代码结构
/src
/poreA
- a1.h
- a1.cpp
/poreB
- b1.h
- b1.cpp
/poreC
- c1.h
- c1.cpp
- c2.h
/maincpp
-communicate.h
-communicate.cpp
-network.h
-network.cpp
-mainfile.cpp
-mainfile.h
每个文件夹(poreA、poreB、poreC)都有自己的make文件
c1.h
#include "a1.h"
// struct definitions are defined here
communicate.h
#include "../poreC/include/c1.h"
#ifndef POREC_H_
#define POREC_H_
network.h
#include "communicate.h"
mainfile.h
#include "network.h"
mainfile.cpp
#include "mainfile.h"
#include "network.h"
当我尝试编译时,
$ gcc -c mainfile.cpp
我得到错误
../../poreC/include/c1.h: fatal error: a1.h, no such file or directory
#include "a1.h"
我试图从类似的帖子中理解这个概念,但无法解决这个问题
【问题讨论】:
-
使用
gcc -I../path/to/include/将新目录添加到包含搜索路径。您可以根据需要使用任意数量的-I。