简体   繁体   中英

(Compiler error) Why does C++ does not find the .h file even though its there?

I am trying to run a C++ file, namely experiment.cpp. On compiling the .cpp file, I get an error that RL_glue.h does not exist, even though RL_glue.h is in the same directory as the C++ file. I kindly call for your suggestions on this issue. Thanks!

The include is as follows:

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

Though I changed it as suggested in the comment:

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

The compiler I am using is gcc 4.6.3 and the compilation command is g++ -Wall -c "%f"

Correction: With the " .... " change, the compiler found RL_glue.h, however, it peculiarly failed in finding RL_common.h.

The exact compiler error:

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.

Note the compiler error location:

./RL_glue.h:4:23

The error is in RL_glue.h including RL_common.h , not in your include of that file. That's because in line 4 of the file RL_glue.h there is something like:

#include <RL_common.h>

instead of:

#include "RL_common.h"

You can replace that line, or even easier is to add -I. to the compiler option, so that the current directory . is searched no matter the include style.

The rules for finding included files vary with the compiler, and you didn't say which one you use so it is hard to tell... but I'll try anyway.

Usually, when you use #include <file> it is searched in the system directories and when you write #include "file" it is searched in the project directories.

My guess is that you are using the <> style when you should be using the "" syntax.

If that doesn't work you may need to add the current directory to the search path, usually with the -I. compiler option, or if you use an IDE, searching in the project options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM