User forums > Using Code::Blocks
how to add header files
(1/1)
iprogram:
Hey everyone.
I started using code:block just a while back,because i started to learn c, so i was wondering if anyone here know how to include header files.
This is what i do:
#include <FILE_NAME.h>
but it doesn't work it says it can't find that file and i have included in the folder i am writing the program in.
Can any one help.
Thanks in Advance.
stahta01:
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F
From the directions under "For your project"
--- Quote ---- Right click on the project then select Build options
- Select the directories tab
- Add the required paths for compiler and linker.
- Add your specific libraries in the linker tab.
- Pay attention to project settings and target settings.
--- End quote ---
My re-write of the directions; just for the header file portion
Project -> "Build Options"
Make sure the correct target is highlighted on the left side; if you do not know select the project, top one.
Select Tab "Search Directories"
Select Sub-Tab "Compiler"
"Add" the path to the folder that contains the header. Single Folder per line.
Tim S.
fox2:
Hello
I'm fairly new to C programming, but I have some experience with Python. I'm facing a problem that's quite difficult for me to solve. I have actually read these boards all day, and tried to Google this issue that many seemed to had, but I still couldn't figure it out.
The problem is that I can't get additional function to work that is in separate file using the header include code.
I have read that you must add the path link to complier, linker and resource complier from search directories tab, from the project Built options, which I have done, but the error remains the same. That is, "undefined reference to "doubleUp"".
I have also tried to change the #include tag from "#include "test.h"" to "#include "C:\thePathToDir\test.h"" with no effect either.
The only thing that actually makes it work is to change the file extension to .c (as #include "test.h" -> #include "test.c") but I realize that is not the correct way to do it.
Here's a shorter code of my actual problem:
--- Code: ---main.c
---------
#include <stdio.h>
#include <stdlib.h>
#include "test.h"
int main()
{
int number = 4;
int multiply = doubleUp(number);
printf ("%d times 2 equals %d.\n", number, multiply);
return 0;
}
--- End code ---
--- Code: ---test.c
-------
#include "test.h"
int doubleUp(int number)
{
return number*2;
}
--- End code ---
--- Code: ---test.h
-------
int doubleUp(int number);
--- End code ---
Here's a screenshot of the Code blocks project view. Is there anything wrong there? Shouldn't the .h and .c files (test.h and test.c) be under the project three?
[IMG=http://img862.imageshack.us/img862/1034/guia.png][/IMG]
Any help would be deeply appreciated.
Jenna:
Right click your project and chose "Add files" to add both files, or "Add files recursively" to add a subdirectory and all including files.
fox2:
Thanks for the quick reply, works like a charm now
Navigation
[0] Message Index
Go to full version