home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18151 < prev    next >
Encoding:
Text File  |  1992-12-17  |  1.3 KB  |  44 lines

  1. Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!not-for-mail
  2. From: ren@function.mps.ohio-state.edu (Liming Ren)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to call C++ functions in a C program?
  5. Date: 17 Dec 1992 15:30:02 -0500
  6. Organization: Department of Mathematics, The Ohio State University
  7. Lines: 32
  8. Message-ID: <1gqo0aINN5jj@function.mps.ohio-state.edu>
  9. References: <1gqbepINNt6s@function.mps.ohio-state.edu> <1gqe3lINNs1v@eagle.natinst.com> <SCHOUTEN.92Dec17125550@sp95.csrd.uiuc.edu>
  10. NNTP-Posting-Host: function.mps.ohio-state.edu
  11.  
  12. First, I want to thank all those very knowledge people who responsed to my 
  13. question. Some said yes and others saied no. I read all the resopnse carefully. 
  14. It seems to me the answer is somewhere in  between. Is that true that for a C++ 
  15. function to be callable in a C program, it must be written in C style? I tried:
  16.  
  17. foo.c:
  18.  
  19. #include<iostream.h>
  20. //callable from C    
  21.   extern "C" int callable_from_c (int i)
  22. {
  23.   cout<<"Merry Chrismas"<<endl;
  24.   return i;
  25. }
  26.  
  27.  
  28. CC -c foo.c turns out all right!
  29.  
  30. When I call this function in a C program, I get error message as:
  31.  
  32. ld: Undefined symbol 
  33.    _cout 
  34.    _endl__FR7ostream 
  35.    ___ls__7ostreamFPCc 
  36.    ___ct__13Iostream_initFv 
  37.    ___dt__13Iostream_initFv 
  38.  
  39. But if I erase the #include<iostream.h> line and the  cout line,
  40. everything turns out to be all right.
  41.  
  42. Merry Chrismas!
  43.  
  44.