2

我正在尝试运行一个 C++ 文件,即experiment.cpp。在编译 .cpp 文件时,我收到 RL_glue.h 不存在的错误,即使 RL_glue.h 与 C++ 文件位于同一目录中。我恳请您就这个问题提出建议。谢谢!

包括如下:

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <RL_glue.h>
#include <RL_common.h>

虽然我按照评论中的建议进行了更改:

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include "RL_glue.h"
#include "RL_common.h"

我使用的编译器是 gcc 4.6.3,编译命令是 g++ -Wall -c "%f"

更正:随着“....”的变化,编译器找到了 RL_glue.h,然而,它却特别找不到 RL_common.h。

确切的编译器错误:

g++ -Wall -c "experiment.cpp" (in directory: /home/issam/Helicopter_Control/Code/Release)
In file included from experiment.cpp:9:0:
./RL_glue.h:4:23: fatal error: RL_common.h: No such file or directory
compilation terminated.
Compilation failed.
4

2 回答 2

5

注意编译器错误位置:

./RL_glue.h:4:23

错误是在includeRL_glue.hRL_common.h,而不是在您对该文件的 include 中。那是因为在文件 RL_glue.h 的第 4 行中有类似的内容:

#include <RL_common.h>

代替:

#include "RL_common.h"

您可以替换该行,或者更简单的是添加-I.到编译器选项,以便.搜索当前目录,无论包含样式如何。

于 2013-03-04T21:24:52.020 回答
2

查找包含文件的规则因编译器而异,而且你没有说你使用的是哪一个,所以很难说......但无论如何我都会尝试。

通常,使用时#include <file>在系统目录中搜索,编写#include "file"时在项目目录中搜索。

我的猜测是,<>当您应该使用""语法时,您正在使用该样式。

如果这不起作用,您可能需要将当前目录添加到搜索路径,通常使用-I.编译器选项,或者如果您使用 IDE,则在项目选项中搜索。

于 2013-03-04T20:58:51.917 回答