User forums > Using Code::Blocks

Code::Blocks fails to find header file?

<< < (2/2)

Radek:
First, it's not a problem of Code Blocks but a problem concerning the compiler. Second, it's really a total bullshit. You cannot solve similar problems this way.

It's the compiler who includes included files. The problems like the yours relates to search paths and to current directories. The quotation marks will not save you if the current directory happens to be different from the .hpp directory. Because you cannot control which directory is the current one at every moment of the compilation, I strongly recommend setting search paths. Make sure that all your include files (be it headers or other files) are on the search path. If the #include directive contains a relative path then the "root" must be on the search path - because the filename will be appended to the search path directories along with the relative path.

There is another problem which you can meet sometimes: cycled #includes. For example:

file first.hpp

--- Code: ---#include <second.hpp>

--- End code ---

file second.hpp

--- Code: ---#include <first.hpp>

--- End code ---

there may be several levels of including in between. Such cycling can result in seemingly not found headers (at least, in GCC) and undefined symbols. #pragma once will not save you. Therefore:

(1) Check your headers for cycling.
(2) Configure include paths in the Project Options menu. Keep all your headers at one place and make sure that the directory with headers is on the include path.

Specifying the full path in the #include directive is the worst thing you can do. Every moving of the project files anywhere will prevent the project from compiling.

Hrach:
I had the same problem with Code::Blocks (or the compiler) not finding the header file. The following worked (I am using Code::Blocks 10.05):

Settings -> Compiler and debugger ... -> Search directories -> Compiler -> Add,

then just add the directory where the header file is.

Jenna:

--- Quote from: Hrach on August 12, 2013, 02:00:15 am ---I had the same problem with Code::Blocks (or the compiler) not finding the header file. The following worked (I am using Code::Blocks 10.05):

Settings -> Compiler and debugger ... -> Search directories -> Compiler -> Add,

then just add the directory where the header file is.

--- End quote ---
Setting paths in global compiler options can be dangerous, unless you want it to be set for every project that uses this compiler.
Forgotten settings in global compiler options are (or have been in the past) one of the most common causes for compiler/linker issues.
Don't do this unless you know exactly what you do !

Navigation

[0] Message Index

[*] Previous page

Go to full version