![](/img/trans.png)
[英]Why does the compiler complain about undefined reference to a constexpr function even though it is defined in another source file?
[英](Compiler error) Why does C++ does not find the .h file even though its there?
我正在尝试运行一个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.
注意编译器错误位置:
./RL_glue.h:4:23
错误发生在RL_glue.h
包括RL_common.h
,而不是包含该文件。 那是因为在文件RL_glue.h的第4行中有类似的东西:
#include <RL_common.h>
代替:
#include "RL_common.h"
您可以替换该行,甚至更简单的方法是添加-I.
到编译器选项,以便当前目录.
无论包含样式,都会被搜索。
查找包含文件的规则因编译器而异,并且您没有说出您使用哪个文件因此很难说...但我还是会尝试。
通常,当您使用#include <file>
,会在系统目录中搜索它,当您编写#include "file"
,会在项目目录中搜索它。
我的猜测是,应该使用""
语法时使用的是<>
样式。
如果这不起作用,您可能需要将当前目录添加到搜索路径,通常使用-I.
编译器选项,或者如果使用IDE,则在项目选项中搜索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.