我有以下文件夹文件层次结构:
src/
Fuelable.h
Fuelables/
PetrolCar.h
PetrolCar.cpp
PetrolCar.h:
#include "Fuelable.h"
PetrolCar.cpp:
#include "PetrolCar.h"
为了进行此编译,我添加了src文件夹以包含本手册中的路径: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Ftasks%2Fcdt_t_proj_paths.htm
包含代码未突出显示为错误。但是当我尝试构建它失败时,有关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]
有趣的是, intellisence可以看到所有文件。
如果我从命令行编译:
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.
答案 0 :(得分:1)
让我们说你会分发一个库机器。包含层次结构可以是:
some_local_or_general_or_system_include_directory
- Machines
- Fuelables
然后,您可以#include <Machines/Fuelable.h>
或#include <Machines/Fuelables/PetrolCar.h>
拥有一个包含目录。否则,您必须将每个目录添加到包含路径。