944,135 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 6084
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 5th, 2006
0

Linking 2 files.

Expand Post »
Hi!

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

Thanks
Ami
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
amishosh is offline Offline
59 posts
since Oct 2006
Oct 5th, 2006
0

Re: Linking 2 files.

What compiler are you using?
Reputation Points: 53
Solved Threads: 6
Junior Poster in Training
Inanna is offline Offline
90 posts
since Sep 2006
Oct 5th, 2006
0

Re: Linking 2 files.

Borland C++ 3.1
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
amishosh is offline Offline
59 posts
since Oct 2006
Oct 5th, 2006
0

Re: Linking 2 files.

  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.
Reputation Points: 53
Solved Threads: 6
Junior Poster in Training
Inanna is offline Offline
90 posts
since Sep 2006
Oct 5th, 2006
0

Re: Linking 2 files.

Yea I know I need to declare.
Where exactly do I type:
  1. C:\>bcc ami.c freidman.c

Thanks
Ami
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
amishosh is offline Offline
59 posts
since Oct 2006
Oct 5th, 2006
0

Re: Linking 2 files.

At the command prompt. The path from the start button is something like Start->Programs->Accessories->Command Prompt.
Reputation Points: 53
Solved Threads: 6
Junior Poster in Training
Inanna is offline Offline
90 posts
since Sep 2006
Oct 5th, 2006
0

Re: Linking 2 files.

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
amishosh is offline Offline
59 posts
since Oct 2006
Oct 5th, 2006
0

Re: Linking 2 files.

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.
Reputation Points: 53
Solved Threads: 6
Junior Poster in Training
Inanna is offline Offline
90 posts
since Sep 2006
Oct 5th, 2006
0

Re: Linking 2 files.

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
amishosh is offline Offline
59 posts
since Oct 2006
Oct 5th, 2006
0

Re: Linking 2 files.

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. }
Reputation Points: 53
Solved Threads: 6
Junior Poster in Training
Inanna is offline Offline
90 posts
since Sep 2006

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: Createdialog_box Error.
Next Thread in C Forum Timeline: Problem starting a homework problem for class. Please help!





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


Follow us on Twitter


© 2011 DaniWeb® LLC