Author Topic: #include File Error  (Read 7048 times)

Offline Ertzel

  • Single posting newcomer
  • *
  • Posts: 2
#include File Error
« on: February 16, 2011, 03:35:35 am »
So im trying to include a file into my current project. I have the project all setup with both files in it, then when I try to include the one page with the other im getting the error

"C:\Users\owner\Desktop\Game Development\C++\Tests\Programs\Visual\Button\Maze\main.cpp|4|Data.h: No such file or directory"

my include looks like this...

#include <Data.h>

Data.h is in the same folder as main.cpp and the same folder as the whole project is (the Maze folder). If I change the include to look like this...

#include <C:\Users\owner\Desktop\Game Development\C++\Tests\Programs\Visual\Button\Maze\Data.h>

Then it works fine with no errors and loads the data from Data.h. My question is, why do I have to put the whole path towards Data.h instead of just <Data.h>, Its really annoying to have to write out the whole patch for each file I include in the project.

(This is my first day using CodeBlocks so sorry if this is a retarded question)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: #include File Error
« Reply #1 on: February 16, 2011, 08:25:37 am »
Setup a project and adjust the include directories from the project settings. See the Code::Blocks manual for details.
http://www.codeblocks.org/docs/main_codeblocks_en.html
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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: #include File Error
« Reply #2 on: February 16, 2011, 08:52:41 am »
The problem you have is not C::B, it's the way the compiler searches for headers.
If you use "<" and ">" to include the header-file, it searches in the systems default directory and the explicitely set include-directories.

There are thre possible solutions:
  • use double-quotes to include the header instead of the angle-brackets
  • explicitely set the folder to the compilers search dirs on project (or target) level
  • make sure the checkboxes "Settings -> Compiler and debugger -> Global compiler settings -> [your compiler] -> Build options -> Explicitely add [...]" are checked

Offline Ertzel

  • Single posting newcomer
  • *
  • Posts: 2
Re: #include File Error
« Reply #3 on: February 16, 2011, 10:20:06 am »
There are thre possible solutions:
  • use double-quotes to include the header instead of the angle-brackets

Thanks both of you, changing the < > to " " fixed it for me and now its working with just putting #include "Data.h"