Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Eclipse没有看到我的c++;从单独的文件夹中包括_C++_Eclipse_Include - Fatal编程技术网

C++ Eclipse没有看到我的c++;从单独的文件夹中包括

C++ Eclipse没有看到我的c++;从单独的文件夹中包括,c++,eclipse,include,C++,Eclipse,Include,我有以下文件夹文件层次结构: src/ Fuelable.h Fuelables/ PetrolCar.h PetrolCar.cpp PetrolCar.h: #include "Fuelable.h" #include "PetrolCar.h" PetrolCar.cpp: #include "Fuelable.h" #include "PetrolCar.h" 为了进行此编译,我添加了src文件夹以包括本手册中的路径: 包含代码未作为错误突出显示。但是

我有以下文件夹文件层次结构:

src/
  Fuelable.h
  Fuelables/
    PetrolCar.h
    PetrolCar.cpp
PetrolCar.h:

#include "Fuelable.h"
#include "PetrolCar.h"
PetrolCar.cpp:

#include "Fuelable.h"
#include "PetrolCar.h"
为了进行此编译,我添加了src文件夹以包括本手册中的路径:

包含代码未作为错误突出显示。但是,当我尝试构建时,它失败了,出现了关于makefile的错误:

Building file: ../src/Fuelables/PetrolCar.cpp
In file included from ../src/Fuelables/PetrolCar.cpp:8:0:
Invoking: GCC C++ Compiler
../src/Fuelables/PetrolCar.h:12:22: fatal error: Fuelable.h: No such file or directory
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Fuelables/PetrolCar.d" -MT"src/Fuelables/PetrolCar.d" -o "src/Fuelables/PetrolCar.o" "../src/Fuelables/PetrolCar.cpp"
compilation terminated.
make: *** [src/Fuelables/PetrolCar.o]
有趣的是,智能传感器可以看到所有文件

如果我从命令行编译:

sashko@sashko-1225C:~/workspaceEclipse/FuelingSystem/src/Fuelables$ g++ PetrolCar.cpp -I 
/home/sashko/workspaceEclipse/FuelingSystem/src/Fuelable.h
cc1plus: warning: /home/sashko/workspaceEclipse/FuelingSystem/src/Fuelable.h: not a directory [enabled by default]
In file included from PetrolCar.cpp:8:0:
PetrolCar.h:12:22: fatal error: Fuelable.h: No such file or directory
compilation terminated.

假设您将分发一个图书馆机器。包含层次结构可以是:

some_local_or_general_or_system_include_directory
- Machines
  - Fuelables

然后您可以
#include
#include
拥有一个包含目录。否则,您必须将每个目录添加到include路径。

在命令行上编译。将适当的
-I
选项添加到
g++
您是否尝试过
#包括“./Fuelable.h”
以指定文件位于上一个目录中?@Basile Starynkevitch,适当是什么意思?更新的问题。@Gmercer015我做了,但我听说这是一种糟糕的风格。此外,如果我想包含一个很远的文件,例如:“ProjectFolder/boost/date\u time/gregorian/gregorian.hpp”,那么该怎么办?Fuelable.h是文件夹“Fuelables”中实现类的接口。我不能像你建议的那样嵌套文件夹。