C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-11-2009, 03:24 PM   #1
Registered User
 
Join Date: Oct 2009
Posts: 16
Header files

Hi! I've just created a program (.c) and a header (.h) file with all the functions that I use in my program. Of course I don't have any main() function in the header file, which gives me an error: "Undefined symbol _main in module c0.ASM" if I run the .h file. I've also added a line, telling
Code:
#include "functions.h"
to the .c file and if I run the .c file, everything works without errors. So what is the correct way of creating a project? Should the .h file include a main function (which will result to multiple main() declaration) ?

p.s. I'm using Borland C++ 3.1

Last edited by nowber; 11-11-2009 at 03:28 PM.
nowber is offline   Reply With Quote
Old 11-11-2009, 03:47 PM   #2
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
Header files are actually not necessary at all, but if you want to use one, go ahead.

Anyway, no, there should not be a main() in the .h file. Each program can have only one main(). A header is not intended to used by itself.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is offline   Reply With Quote
Old 11-11-2009, 04:02 PM   #3
Registered User
 
Join Date: Oct 2009
Posts: 16
Ok, so I have a functions.h header file (without the main function) and a main.c file. If I add both of them to a project and run it, I get multiple errors saying:

_function1 defined in module MAIN.C is duplicated in module FUNCTIONS.H
_function2 defined in module MAIN.C is duplicated in module FUNCTIONS.H
etc...

although I have defined them ONLY in functions.h file. The same error is produced for the array of records, that I've defined in functions.h. Any idea of what I'm doing wrong?

Here's a small example how it looks in general:

Code:
(functions.h)

int number (int low, int high);

struct rec {
	char name[33];
	};
struct rec arr[5]; // array of records


int number (int low, int high){
... some actions
}

(main.c)

#include "functions.h"

number(1,50)

Last edited by nowber; 11-11-2009 at 04:08 PM.
nowber is offline   Reply With Quote
Old 11-11-2009, 04:09 PM   #4
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
Quote:
Originally Posted by nowber View Post
If I add both of them to a project and run it,
I am not familiar with the Borland compiler, so I presume this means you are doing something with the IDE?

Anyway, normatively you just include the .h file in your .c file:
Code:
#include "myheader.h"
Note that is not <myheader.h>. This presumes both files are in the same directory.

Then you just compile the .c file and the .h file will be included.

[edit] okay, it looks like that is what you are already doing....hmmm
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to make the best use of header files alanb C++ Programming 4 08-31-2009 04:45 PM
what am I missing? (Program won't compile) steals10304 C Programming 3 08-25-2009 03:01 PM
Header files and multiple definitions sjweinberg C++ Programming 16 07-17-2009 05:59 PM
#include header files or .cpp files? DoctorX C++ Programming 3 12-23-2006 12:21 PM
Request for comments Prelude A Brief History of Cprogramming.com 15 01-02-2004 10:33 AM


All times are GMT -6. The time now is 07:51 PM.


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