![]() |
| | #1 |
| Registered User Join Date: Jan 2002
Posts: 1,020
| Include a header file, but where does the header file look in? 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 | |
| | #2 |
| Code Goddess 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 | |
| | #3 |
| Confused 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 | |
| | #4 |
| Registered User 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;
}
Code: int sum (int a, int b); gcc -c main.c gcc -c sum.c gcc -o finalprog sum.c main.c ??? thx thx !!! |
| PutoAmo is offline | |
| | #5 |
| Registered User 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 | |
| | #6 |
| Im a Capricorn Join Date: Feb 2002
Posts: 192
| 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 | |
| | #7 |
| Registered User 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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |