943,865 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 549
  • C RSS
Jan 22nd, 2009
0

linking of .c and .h files

Expand Post »
hi i m mohan sahu.i m using turbo c( borland compiler) and working with windows xp. i have one header file say myheader.h having only declarations of all functions and one myfunc.c file having only definitions of all function without main and i m including header file with #include "myheader.h" in this program.when i m using this header file in other program say func.c where i m including header by #include "myheader.h" but compiler is showing the error "unable to include myheader.h" .can anyone suggest me how to compile and link these files so that it will work properly.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mohan_198505 is offline Offline
4 posts
since Jan 2009
Jan 22nd, 2009
0

Re: linking of .c and .h files

One possible reason can be that 'func.c' is not in the same directory/folder as 'myheader.h' and if this is the case then either you can put the 'myheader.h' in the same directory/folder as 'func.c'

OR

You can put the 'myheader.h' in some standard path where your turbo c compiler searches for standard .h files(but in this case you have to change the line from
  1. #include "myheader.h"

to

  1. #include <myheader.h>

Hope it helps....
Reputation Points: 13
Solved Threads: 5
Light Poster
me_ansh is offline Offline
44 posts
since Jan 2009
Jan 23rd, 2009
0

Re: linking of .c and .h files

I have a small example how linking is to be done.
Suppose i have two program named imp.c and imp1.c
imp.c contains
  1. void arr()
  2. {
  3. printf("hello ajay");
  4. }
imp1.c contains
  1. void art()
  2. {
  3. printf("My name is ajay");
  4.  
  5. }
then linking of above two programs with the program imp3.c
is done as
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<g:\tc\bin\imp.cpp>
  4. #include<g:\tc\bin\imp1.cpp>
  5. int main(void)
  6. {
  7. clrscr();
  8. printf("this is the imp one:");
  9. art();
  10. arr();
  11. return(0);
  12. }
Reputation Points: 6
Solved Threads: 9
Junior Poster in Training
ajay.krish123 is offline Offline
90 posts
since Nov 2008
Jan 24th, 2009
0

Re: linking of .c and .h files

Reputation Points: 6
Solved Threads: 9
Junior Poster in Training
ajay.krish123 is offline Offline
90 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Arrays and Pointer Arithmetic Question
Next Thread in C Forum Timeline: Preventing code from using code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC