Linking 2 files.

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 58
Reputation: amishosh is an unknown quantity at this point 
Solved Threads: 0
amishosh amishosh is offline Offline
Junior Poster in Training

Linking 2 files.

 
0
  #1
Oct 5th, 2006
Hi!

I have functions defined in ami.c and want to call them from friedman.c how do I link the 2?

Thanks
Ami
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: Linking 2 files.

 
0
  #2
Oct 5th, 2006
What compiler are you using?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 58
Reputation: amishosh is an unknown quantity at this point 
Solved Threads: 0
amishosh amishosh is offline Offline
Junior Poster in Training

Re: Linking 2 files.

 
0
  #3
Oct 5th, 2006
Borland C++ 3.1
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: Linking 2 files.

 
0
  #4
Oct 5th, 2006
  1. C:\>bcc ami.c freidman.c
But that'll only work if freidman.c includes declarations for the functions. Otherwise it won't compile because it doesn't know that the functions exist. You can declare them directly or use a header file. The better way is to use a header file.
  1. /* ami.h */
  2. #ifndef AMI
  3. #define AMI
  4.  
  5. void function(void);
  6.  
  7. #endif
  1. /* ami.c */
  2. #include "ami.h"
  3.  
  4. void function(void)
  5. {
  6. /* ... */
  7. }
  1. /* freidman.c */
  2. #include "ami.h"
  3.  
  4. int main(void)
  5. {
  6. function();
  7. return 0;
  8. }
Last edited by Inanna; Oct 5th, 2006 at 8:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 58
Reputation: amishosh is an unknown quantity at this point 
Solved Threads: 0
amishosh amishosh is offline Offline
Junior Poster in Training

Re: Linking 2 files.

 
0
  #5
Oct 5th, 2006
Yea I know I need to declare.
Where exactly do I type:
  1. C:\>bcc ami.c freidman.c

Thanks
Ami
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: Linking 2 files.

 
0
  #6
Oct 5th, 2006
At the command prompt. The path from the start button is something like Start->Programs->Accessories->Command Prompt.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 58
Reputation: amishosh is an unknown quantity at this point 
Solved Threads: 0
amishosh amishosh is offline Offline
Junior Poster in Training

Re: Linking 2 files.

 
0
  #7
Oct 5th, 2006
Yea that's what I thought.
I tried it it didn't recognize bcc.
I tried to go to the specific file directory and even the BorlanC directory. None of them worked.

I must be doing something worng.
Thanks
Ami
Last edited by amishosh; Oct 5th, 2006 at 9:14 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: Linking 2 files.

 
0
  #8
Oct 5th, 2006
I'm prolly forgetting the name of the executable. It might be bcc16 or bcc32 as well. Check the bin directory of where you installed the compiler and you'll see it.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 58
Reputation: amishosh is an unknown quantity at this point 
Solved Threads: 0
amishosh amishosh is offline Offline
Junior Poster in Training

Re: Linking 2 files.

 
0
  #9
Oct 5th, 2006
Ok!
Yes it IS bcc.
I put the 2 files in the same directory as BIN and then ran:
  1. bcc file1.c file2.c
It opened a MS-DOS (Im using Win XP) window for a sec and closed. I assume it did something.
Now in file 2 I have this:
  1. /* file2.c */
  2. #include <stdio.h>
  3. int main()
  4. {
  5. extern int i;
  6. /* get_j(void) is in file1.c */
  7. int get_j(void);
  8.  
  9.  
  10. printf("i == %d\n", ++i);
  11. printf("j == %d\n", get_j());
  12. return 0;
  13. }

It doesnt recognize "get_j". I diclared get_j in file1.c
Any idea why?

Thanks
Ami
Last edited by amishosh; Oct 5th, 2006 at 9:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: Linking 2 files.

 
0
  #10
Oct 5th, 2006
Just a hunch, but try this and paste the error that you get.
  1. /* file2.c */
  2. #include <stdio.h>
  3.  
  4. int get_j(void);
  5.  
  6. int main()
  7. {
  8. extern int i;
  9.  
  10. printf("i == %d\n", ++i);
  11. printf("j == %d\n", get_j());
  12.  
  13. return 0;
  14. }
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC