C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-01-2002, 07:33 AM   #1
Registered User
 
Nutshell's Avatar
 
Join Date: Jan 2002
Posts: 1,020
Include a header file, but where does the header file look in?

HI,

If i include a header file, where does the header file ( or more correctly - the compiler ) look in to find the function definitions and stuff that are declared in the header file? Because header file is only for declaring things, the actual code must reside somewhere else? I know the standard libraries reside in the "Include" directory in the compiler's directory. But if i have a custom source file and a header file, i include the header file, but where should i put the custom source file so it can be found by the compiler? The Include dir? Anywhere else?

thnx thnx
Nutshell is offline   Reply With Quote
Old 04-01-2002, 11:17 AM   #2
Code Goddess
 
Prelude's Avatar
 
Join Date: Sep 2001
Posts: 9,661
<header.h>
This is a header file that comes with your compiler, it can be found in the Include directory. The < > tokens denote this feature.

"header.h"
A custom header which you yourself wrote or downloaded somewhere. This header should be placed in the same directory as your source file which uses it, a feature which is denoted by the " " tokens.

-Prelude
__________________
My best code is written with the delete key.
Prelude is offline   Reply With Quote
Old 04-01-2002, 12:02 PM   #3
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,122
You should link all the files together with the linker when compiling (*.c/*.cpp files, not the *.h files).
__________________
MagosX.com

Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Magos is offline   Reply With Quote
Old 04-01-2002, 06:01 PM   #4
Registered User
 
PutoAmo's Avatar
 
Join Date: Mar 2002
Posts: 72
So... let's say I have a program (main.c) which adds two integers by calling a function sum() :

Code:
int sum(int a, int b)
{
   return a + b;
}

Code:
#include <stdio.h>
#include "myheaders.h"

int main (void)
{
   int a = 3;
   int b = 4;

   printf ("%d\n", sum (a,b));

   return 0;
}
where myheaders.h looks like:
Code:
int sum (int a, int b);
shall I just ...

gcc -c main.c
gcc -c sum.c
gcc -o finalprog sum.c main.c

???

thx thx !!!
PutoAmo is offline   Reply With Quote
Old 04-02-2002, 02:58 AM   #5
Registered User
 
Nutshell's Avatar
 
Join Date: Jan 2002
Posts: 1,020
Thnx prelude, u answered my question: source file should be placed in the same directory

But thnx to all guys too who posted.
Nutshell is offline   Reply With Quote
Old 04-02-2002, 03:43 AM   #6
Im a Capricorn
 
vsriharsha's Avatar
 
Join Date: Feb 2002
Posts: 192
Thumbs up A more polished version...

A better way of putting preludes answer....(i guess)

When you #include a header file inclosed in < >, the compiler looks for that header file in the INCLUDE DIRECTORY PATH specified in ur configuration file. But if u include the header file enclosed in " " then the C-Compiler will look for the header file in the current directory. therefore u can also #include ur custom headers in the following way..
#include"..\myproj\defs.h"

Hope you got the point...

Regards,
Sriharsha.
__________________
Help everyone you can
vsriharsha is offline   Reply With Quote
Old 04-02-2002, 05:46 AM   #7
Registered User
 
Nutshell's Avatar
 
Join Date: Jan 2002
Posts: 1,020
i know i know how to include custom header files. I was asking where does the compiler look for the source files for the function definitions and stuff that the custom header files contain, and prelude said in the same directory as the custom header file, and that was the answer.
Nutshell is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
cant include libipq.h header file rohit83.ken C Programming 3 04-04-2008 02:41 AM
Need help understanding Header Files Kaidao C++ Programming 11 03-25-2008 10:02 AM
airport Log program using 3D linked List : problem reading from file gemini_shooter C Programming 3 03-04-2005 02:46 PM
MS Visual C++ 6 wont include vector.h in a header file bardsley99 C++ Programming 9 11-06-2003 12:05 PM


All times are GMT -6. The time now is 08:38 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22