如何让Linux g ++正确编译另一个头文件中包含的头文件?

时间:2015-10-07 14:53:27

标签: c++ linux gcc makefile

我有一个关于如何修复以下Linux Makefile代码的问题:

g++  -g -Wall -I"./" -I"../CameraControlLib" -I"./Cameras" -I"../../Utilities/DataServer"  -o Server.o CameraControlLib/Server.cpp

在这种特殊情况下,DataServerLib.h包含CameraControlDefs.h,如下所示。 Ubuntu Linux g++编译器使用DataServerLib.h预处理程序指令正确解析包含文件-I,如下所示。 但是,g++编译器告诉我,即使我将CameraControlDefs.h子目录路径指向-I,也没有../../Utilities/DataServer这样的文件或目录。

In file included from CameraControlLib/DataServer.h:4:0,
                 from CameraControlLib/DataServer.cpp:8:
CameraControlLib/DataServerLib.h:9:31: fatal error: CameraControlDefs.h: No such file or directory
 #include "CameraControlDefs.h"
                               ^
compilation terminated.

我知道如果我使用#include "SomeDir/CameraControlDefs.h",那应该摆脱编译器错误消息。如果有其他方法可以使用全套Linux g++选项,请告知我们。

1 个答案:

答案 0 :(得分:0)

下午好,   这是我刚刚使用g ++编译器在Makefile中测试的一个源代码

INCDIRS:= $(addprefix -I,$(shell find ../Utilities/DataServer -type d -print))