RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 7023 | Replies: 44
Reply
Join Date: Mar 2006
Posts: 25
Reputation: Moe is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

Help How to link .c file and .h file

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,642
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 986
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

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

  #2  
Mar 21st, 2006
.h files are includes in .c files
// myfile.c
//
#include "myheader.h"
// 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  
Join Date: Mar 2006
Posts: 25
Reputation: Moe is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

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

  #3  
Mar 21st, 2006
Originally Posted by Ancient Dragon
.h files are includes in .c files
// myfile.c
//
#include "myheader.h"
// 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  
Join Date: Mar 2006
Posts: 25
Reputation: Moe is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

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

  #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  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,642
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 986
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

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

  #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.
#pragma warning(disable: 4996)
Reply With Quote  
Join Date: Mar 2006
Posts: 25
Reputation: Moe is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

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

  #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  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,642
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 986
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

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

  #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  
Join Date: Mar 2006
Posts: 25
Reputation: Moe is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Moe Moe is offline Offline
Light Poster

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

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

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

  #9  
Mar 21st, 2006
You are also ancient dragon.
Are you good?
It is just joke.
Please guide me.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,642
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 986
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:43 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC