如何要求Linux g++正确编译包含在另一个头文件中的头文件

How to ask Linux g++ to correctly compile header files contained within another header file?

本文关键字:文件 包含 另一个 编译 Linux g++      更新时间:2023-10-16

我有一个关于如何修复以下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++编译器告诉我,即使我将-I子目录路径指向../../Utilities/DataServer,也没有CameraControlDefs.h这样的文件或目录。

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++的全部选项来做到这一点。

下午好!这是一个解决方案,我刚刚测试了一个Makefile使用g++编译器

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