Code::Blocks
October 02, 2014, 12:17:17 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Don't forget to check the Nightly builds in the appropriate forum.
 
   Home   Help Search Login Register  :: WebsiteWiki  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: how to add header files  (Read 26364 times)
iprogram
Newcomer
*
Offline Offline

Posts: 1


« on: May 19, 2011, 05:43:56 am »

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.
Logged
stahta01
Lives here!
****
Offline Offline

Posts: 4394


WWW
« Reply #1 on: May 19, 2011, 03:32:57 pm »

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.

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.



Logged

C Programmer working to learn more about C++.
Compiling CB Trunk against wxWidgets WX_3_0_BRANCH branch.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org/index.php?title=Main_Page
fox2
Newcomer
*
Offline Offline

Posts: 2


« Reply #2 on: January 20, 2012, 09:56:39 pm »

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;
}

Code:
test.c
-------
#include "test.h"

int doubleUp(int number)
{
return number*2;
}

Code:
test.h
-------
int doubleUp(int number);

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.
« Last Edit: January 20, 2012, 09:59:47 pm by fox2 » Logged
jens
Administrator
Lives here!
*****
Offline Offline

Posts: 6610



WWW
« Reply #3 on: January 20, 2012, 10:20:36 pm »

Right click your project and chose "Add files" to add both files, or "Add files recursively" to add a subdirectory and all including files.
Logged

Regards

Jens  Debian - nightlies (and release) : http://apt.jenslody.de/ Fedora [18 - 20]- and CentOS/RedHat [5, 6 & 7] - nightlies : http://rpm.jenslody.de/
fox2
Newcomer
*
Offline Offline

Posts: 2


« Reply #4 on: January 20, 2012, 10:29:48 pm »

Thanks for the quick reply, works like a charm now
Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!