News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Problems with including header files.

Started by Mythion, September 11, 2006, 09:26:45 PM

Previous topic - Next topic

Mythion

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:


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


and when i used build i got these errors:

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?

kelo81

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


Brain Damage

#3
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

crzysdrs

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

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

stahta01

#6
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


   
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Brain Damage

#7
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?



stahta01

#8
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
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Brain Damage

Thank you very much, now works perfectly.