How to link .c file and .h file

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 36
Reputation: Moe is an unknown quantity at this point 
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

How to link .c file and .h file

 
0
  #1
Mar 21st, 2006
Hello everybody!
I would like to know "how to link header file (.h file ) and source file (.c file ) in c.
I have downloaded many .h files and .c files. I have noticed that the functions are declared in .h files and denined in .c files. I don't know how to link them in main program.
Please explain me.
thanks in advance,
Moe
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,342
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to link .c file and .h file

 
0
  #2
Mar 21st, 2006
.h files are includes in .c files
  1. // myfile.c
  2. //
  3. #include "myheader.h"
  4. // rest of c program here

Then run your compiler against all the *.c files. It will create *.obj files which can be used by the linker to create the executable file.

Beyone that, how to do all the above depends on the compiler and operating system you are using.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 36
Reputation: Moe is an unknown quantity at this point 
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

Re: How to link .c file and .h file

 
0
  #3
Mar 21st, 2006
Originally Posted by Ancient Dragon
.h files are includes in .c files
  1. // myfile.c
  2. //
  3. #include "myheader.h"
  4. // rest of c program here

Then run your compiler against all the *.c files. It will create *.obj files which can be used by the linker to create the executable file.

Beyone that, how to do all the above depends on the compiler and operating system you are using.


When I compile *.c files, most of them have many errors.
So I think I can not create obj file.
I have downloaded that for link grammar api.
http://www.link.cs.cmu.edu/link
I think that can not have error.Can you please test that for me.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 36
Reputation: Moe is an unknown quantity at this point 
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

Re: How to link .c file and .h file

 
0
  #4
Mar 21st, 2006
Ancient Dragon

Your mean I have to create obj file by compiling *.c file.Yes, I can compile that.
After that what should i do?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,342
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to link .c file and .h file

 
0
  #5
Mar 21st, 2006
What compiler are you using? If you use Microsoft Visual C++ 2005 Express, the download includes project files.

If that is your compiler, then the compiler will spew out a whole bunch of warnings about using deprecated C functions. you can disable the warning with a pragma. put this at the top of link-includes.h. Otherwise everyting compiled and linked ok for me using VC Express compiler.
  1. #pragma warning(disable: 4996)
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 36
Reputation: Moe is an unknown quantity at this point 
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

Re: How to link .c file and .h file

 
0
  #6
Mar 21st, 2006
Don't laugh at me.
I am using turbo c compiler. It is an ancient software.
I also try to use Borland 5.5. But that gives many error when I compile .c file.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,342
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to link .c file and .h file

 
0
  #7
Mar 21st, 2006
Originally Posted by Moe
Don't laugh at me.
I am using turbo c compiler. It is an ancient software.
I also try to use Borland 5.5. But that gives many error when I compile .c file.
:cheesy: :cheesy: :cheesy: :cheesy: :cheesy: :cheesy: :cheesy:

trash those old ancient compilers! you can get pretty good free compilers, such as the Express I mentioned previously or Dev-C++ from www.bloodshed.net.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 36
Reputation: Moe is an unknown quantity at this point 
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

Re: How to link .c file and .h file

 
0
  #8
Mar 21st, 2006
I think I cannot use vc.
I would like to write my project in c.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 36
Reputation: Moe is an unknown quantity at this point 
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

Re: How to link .c file and .h file

 
0
  #9
Mar 21st, 2006
You are also ancient dragon.
Are you good?
It is just joke.
Please guide me.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,342
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to link .c file and .h file

 
0
  #10
Mar 21st, 2006
Originally Posted by Moe
You are also ancient dragon.
Are you good?
It is just joke.
Please guide me.
Sorry -- I couldn't resist the laughter.

you cannot use TC because it is too old and does not know about long file names -- file names that are longer than 8 characters followed by a perios and 3 characters for the extension. That is the ancient MS-DOS format. The files in the download you are trying to compile have long filenames.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC