home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11810 < prev    next >
Encoding:
Text File  |  1992-07-31  |  2.0 KB  |  71 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mcsun!dxcern!dxcern!kardanev.lepapp.none
  3. From: kardanev.lepapp.none@hanoi.cern.ch (A. Kardanev)
  4. Subject: Re: linking gcc code with CC code
  5. In-Reply-To: kps@cunixb.cc.columbia.edu's message of Thu, 30 Jul 1992 18:20:47 GMT
  6. Message-ID: <KARDANEV.LEPAPP.NONE.92Jul31094445@hanoi.cern.ch>
  7. Sender: news@dxcern.cern.ch (USENET News System)
  8. Organization: European Laboratory for Particle Physics (CERN) Switzerland
  9. References: <1992Jul30.182047.18971@news.columbia.edu>
  10. Date: Fri, 31 Jul 1992 08:44:45 GMT
  11. Lines: 58
  12.  
  13. In article <1992Jul30.182047.18971@news.columbia.edu> kps@cunixb.cc.columbia.edu (Karthik P Sheka) writes:
  14.    Is it possible to link gcc created object files with CC created object
  15.    files?  I've tried doing so but it seems that the c functions cannot call
  16.    the c++ functions, even though the c++ functions are not in any class.
  17.    Sample code follows... (The error returned is Undefined symbol: routine2)
  18.  
  19.    /*****C++ code*****/
  20.    #include <iostream.h>
  21.    extern "C"{
  22.    int routine1(void);
  23.    };
  24.  
  25.    int main(void)
  26.    {
  27.      cout << routine1();
  28.    }
  29.    static int routine2(void)
  30.    {
  31.      return 2;
  32.    }
  33.  
  34.  
  35.    /*****C code*****/
  36.    extern int routine2();
  37.  
  38.    int routine1(void)
  39.    {
  40.      return(routine2());
  41.    }
  42.  
  43. Just change your C++ code to:
  44. /*****C++ code*****/
  45. #include <iostream.h>
  46. extern "C"{
  47. int routine1(void);
  48. int routine2(void);        // Added this for calling from usual C
  49. };
  50.  
  51. int main(void)
  52. {
  53.   cout << routine1();
  54. }
  55. int routine2(void)        // Removed "static" declaration to make this
  56.                 // routine "global"
  57. {
  58.   return 2;
  59. }
  60.  
  61.  
  62. Hope this help... but there may be some other problem in compatibility
  63. your gcc and CC...
  64. --
  65. -------------------------------------------------------------------------
  66.  KARDANEV Alexandre            | SL Division    
  67.  Email: kardanev@hanoi.cern.ch        | Building 864, 1-A02        
  68.  Voice:    + 41-22-767-5165        | CERN 1211 Geneva 23        
  69.                     | Switzerland            
  70. -------------------------------------------------------------------------
  71.