Author Topic: Problems with including header files.  (Read 5737 times)

Mythion

  • Guest
Problems with including header files.
« on: September 11, 2006, 09:26:45 pm »
Hi, i am new to the forum and new to code::blocks and i have a problem with the console app, i wrote a simple celsius to fahrenheit converter(i needed one  :lol:) and i included the following headers:

Code
#include <cstdio>
#include <cstdlib>
#include <iostream>

and when i used build i got these errors:
Code
cstdio: no such file or directory
cstdlib: no such file or directory
iostream: no such file or directory

this happens only in console apps, what can i do to fix this problem?

Offline kelo81

  • Multiple posting newcomer
  • *
  • Posts: 86
Re: Problems with including header files.
« Reply #1 on: September 11, 2006, 10:12:56 pm »
What compiler are you using?, if you are using a nightly build, you have to link the compiler directories on the comiler configuration (the "include" path)
Ezequiel Ruiz
Tango/04 consultant
www.tango04.com

Mythion

  • Guest
Re: Problems with including header files.
« Reply #2 on: September 14, 2006, 08:26:08 pm »
oh thanks, i forgot that.

Brain Damage

  • Guest
Re: Problems with including header files.
« Reply #3 on: September 14, 2006, 11:07:33 pm »
hello i'm new too, i'm not sure where i should post this post, is feature request/help, feel free to move if needed.
i got the same error (doesn't find header's files) , the only difference is that my header file was in the same folder of my source file; now is there an option to make it to search for the header files in the project's folder too? shouldn't it does automatically? (without the need to reference them inside the include paths) if no, then i will post a feature request..

and i apologize for my bad english   :P
« Last Edit: September 14, 2006, 11:17:31 pm by Brain Damage »

Offline crzysdrs

  • Single posting newcomer
  • *
  • Posts: 7
Re: Problems with including header files.
« Reply #4 on: September 14, 2006, 11:26:46 pm »
If you want to include a file that is in your project directory just use quotation marks. The <> are reserved for libraries (located in the libraries directorys, OS dependent) whereas custom made header files should use "" with a relative path name inside to include them.

Brain Damage

  • Guest
Re: Problems with including header files.
« Reply #5 on: September 14, 2006, 11:39:26 pm »
the problem is that that program isn't written by me, i just wanted to add few changes then compile it, the strange thing is that it compiles on other compilers like .NET C++ using <> for the includes, i guess i'll have to manually include the project's folder inside the include paths becasue i'm not gonna edit 200+ files to replace the includes syntax :x

thanks for the help

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Problems with including header files.
« Reply #6 on: September 15, 2006, 12:49:23 am »
Things to Try

Note: in theory option 2 should only be done for <> includes but, I have found it helps to compile code that I wish to not have to edit for "" includes also.
Note: I have yet to get the project to link so it might be a bad decision.

Note: On doing option 1; I would suggest coping the compiler setting and modify the copy; then setting your project to use the modified copy.

1. Change the "Global Compiler Settings" for the Compiler you are using by "Other" Tab
     Checking "Explicitely add currently compiling file directory ..."
   OR/AND
     Checking "Explicitely add project top level directory ..."

2. "Project" -> "Build Options" set values "Compiler", "Linker" or "Resource Compiler" under "directories" tab

Tim S


   
« Last Edit: September 15, 2006, 12:51:17 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Brain Damage

  • Guest
Re: Problems with including header files.
« Reply #7 on: September 15, 2006, 01:41:51 pm »
the program is nested this way:

main folder/
---Subfolder1/
-------A.cpp
-------A.h
---Subfolder2/
-------B.cpp
-------B.h

now A.cpp contains:
#include <Subfolder1/A.h>
#include <Subfolder1/A.h>

the compiler stops when it checks #include <Subfolder1/A.h> but not with only #include <Subfolder1/A.h>

i know to be totally correct it should be #include <A.h> or #include "A.h", but that syntax works for other IDE, it's just code::blocks that doesn't accept it, i've tried even different compilers with code::blocks but it always does the same error. With other IDEs, it's acceptied.

the option #1 works if i use the syntax #include "A.h" or the syntax #include <A.h>; but not if i use #include <Subfolder1/A.h>, now all the include references are made that way; changing them would be too tedious.

the option #2 works with all syntax, i've included the source's folder inside the include paths and it compiles it.

my problem is: i have few projects with that structure; do have i to add to every single project to the include paths, or is there a variable or a relative reference that i can set in the global compiler settings to avoid to do that for every project?


« Last Edit: September 15, 2006, 01:47:56 pm by Brain Damage »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Problems with including header files.
« Reply #8 on: September 15, 2006, 02:56:59 pm »
main folder/
---project.cbp
---Subfolder1/
-------A.cpp
-------A.h
---Subfolder2/
-------B.cpp
-------B.h

now A.cpp contains:
#include <Subfolder1/A.h>
#include <Subfolder1/A.h>

I have been up for 48 hours straight so I might not make alot of sence.

I would put your project.cbp file in the folder "main folder". And then try to use option 1 of
  Change the "Global Compiler Settings" for the Compiler you are using by "Other" Tab
  Checking "Explicitely add project top level directory ..."

Then the
#include <Subfolder1/A.h>
#include <Subfolder1/A.h>
Should work if I understand everything.

Tim S
« Last Edit: September 15, 2006, 03:01:13 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Brain Damage

  • Guest
Re: Problems with including header files.
« Reply #9 on: September 15, 2006, 03:57:55 pm »
Thank you very much, now works perfectly.