Author Topic: Code::Blocks fails to find header file?  (Read 30694 times)

Offline dominover

  • Multiple posting newcomer
  • *
  • Posts: 46
Code::Blocks fails to find header file?
« on: November 21, 2012, 08:12:48 pm »
The link below refers to a common problem with code::blocks where code::blocks can't see the header file if the .cpp file also contains an include to that header file.

I'm experiencing this kind of problem right now but the below solution won't correct it?  Any clues as to what the below instructions are missing?




http://www.jusuchyne.com/codingchyne/2011/03/codeblocks-failed-to-find-the-header-file/

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Code::Blocks fails to find header file?
« Reply #1 on: November 21, 2012, 08:20:48 pm »
Setting the compiler and linker search directory is one thing you have to do in any IDE, if you do not use standard header laocation like /usr/include .

The so called workaround proposed by the link you have posted is total bullshit.
Never, never, never use absolute paths to header files or compilation will break sooner or later.
Source code will not be portable or usable by others without changing the code itself.

And if the search path is configured properly it will for sure work.
But note: backslashes in include paths (e.g. #include <wx\window.h>) are not allowed and make sure you use the correct case for paths and names.
Backslashes work on windows (mostly) and case doesn't matter there. But for portable code and on linux/mac it's not allowed !!

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Code::Blocks fails to find header file?
« Reply #2 on: November 21, 2012, 08:22:23 pm »
Sorry, but the thread you are pointing to is (excuse my french) but bullshit.

Its missing the basic steps of how to setup a project. If you have compilation unit that include header files, you need to setup a project and setup the compiler include paths accordingly.

If you look at the full compiler log (which is not provided in the other thread) you'll see such mistakes easily. If you experience such an issue, post the full compiler log here and I tell you what you did wrong.

The author of the other thread should read the Code::Blocks manual and try to understand the basics of how a compiler / linker works. This you can do best w/o IDE at the command line - thats what I did before I used IDE's at all. And it keeps me safe from such simple mistakes for the rest of my life.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline dominover

  • Multiple posting newcomer
  • *
  • Posts: 46
Re: Code::Blocks fails to find header file?
« Reply #3 on: November 22, 2012, 04:57:52 am »
So we've confirmed that it's .... b_ _ ..sh__t .  How about some constructive input if you really want to help.  Maybe I will use just the command line one day but at this stage I'm not even going to consider it.

Quote
ts missing the basic steps of how to setup a project

What does this have to do with it?  The link has nothing to do with setting up code::blocks.. It's aimed at solving a particular problem.


Quote
The author of the other thread should read the Code::Blocks manual and try to understand the basics of how a compiler / linker works.

What other thread?   Are we still on the same topic?

Quote
And if the search path is configured properly it will for sure work.

Not in this case.  I know of to configure the search path. 

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Code::Blocks fails to find header file?
« Reply #4 on: November 22, 2012, 08:28:54 am »
So we've confirmed that it's .... b_ _ ..sh__t .  How about some constructive input if you really want to help.  Maybe I will use just the command line one day but at this stage I'm not even going to consider it.
That means you don't want to know what's going on behind the scenes.
But that's needed (in many cases) to see what's going wrong.

Quote
ts missing the basic steps of how to setup a project

What does this have to do with it?  The link has nothing to do with setting up code::blocks.. It's aimed at solving a particular problem.
It's not about setting up Code::Blocks, but a project inside C::B, which is (obviously) not the same.
And without setting up the project correctly, there will no reliable solution !



Quote
The author of the other thread should read the Code::Blocks manual and try to understand the basics of how a compiler / linker works.

What other thread?   Are we still on the same topic?

I guess he meant the thread in the link you posted, a thread is not necessary a thread in our forum.

Quote
And if the search path is configured properly it will for sure work.

Not in this case.  I know of to configure the search path. 
So why don't you come up with the information mentionened by MortenMacFly:
If you look at the full compiler log (which is not provided in the other thread) you'll see such mistakes easily. If you experience such an issue, post the full compiler log here and I tell you what you did wrong.

You want steps to slove your problem, but you seem not to be willing (or able?) to give the necessary information.

By the way, you even miss the basic informations like C::B version, OS, probably compiler and version, etc..

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
Re: Code::Blocks fails to find header file?
« Reply #5 on: November 22, 2012, 09:15:09 am »
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>

file second.hpp
Code
#include <first.hpp>

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.

Offline Hrach

  • Single posting newcomer
  • *
  • Posts: 2
Re: Code::Blocks fails to find header file?
« Reply #6 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.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Code::Blocks fails to find header file?
« Reply #7 on: August 12, 2013, 05:52:37 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.
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 !