home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mcsun!dxcern!dxcern!kardanev.lepapp.none
- From: kardanev.lepapp.none@hanoi.cern.ch (A. Kardanev)
- Subject: Re: linking gcc code with CC code
- In-Reply-To: kps@cunixb.cc.columbia.edu's message of Thu, 30 Jul 1992 18:20:47 GMT
- Message-ID: <KARDANEV.LEPAPP.NONE.92Jul31094445@hanoi.cern.ch>
- Sender: news@dxcern.cern.ch (USENET News System)
- Organization: European Laboratory for Particle Physics (CERN) Switzerland
- References: <1992Jul30.182047.18971@news.columbia.edu>
- Date: Fri, 31 Jul 1992 08:44:45 GMT
- Lines: 58
-
- In article <1992Jul30.182047.18971@news.columbia.edu> kps@cunixb.cc.columbia.edu (Karthik P Sheka) writes:
- Is it possible to link gcc created object files with CC created object
- files? I've tried doing so but it seems that the c functions cannot call
- the c++ functions, even though the c++ functions are not in any class.
- Sample code follows... (The error returned is Undefined symbol: routine2)
-
- /*****C++ code*****/
- #include <iostream.h>
- extern "C"{
- int routine1(void);
- };
-
- int main(void)
- {
- cout << routine1();
- }
- static int routine2(void)
- {
- return 2;
- }
-
-
- /*****C code*****/
- extern int routine2();
-
- int routine1(void)
- {
- return(routine2());
- }
-
- Just change your C++ code to:
- /*****C++ code*****/
- #include <iostream.h>
- extern "C"{
- int routine1(void);
- int routine2(void); // Added this for calling from usual C
- };
-
- int main(void)
- {
- cout << routine1();
- }
- int routine2(void) // Removed "static" declaration to make this
- // routine "global"
- {
- return 2;
- }
-
-
- Hope this help... but there may be some other problem in compatibility
- your gcc and CC...
- --
- -------------------------------------------------------------------------
- KARDANEV Alexandre | SL Division
- Email: kardanev@hanoi.cern.ch | Building 864, 1-A02
- Voice: + 41-22-767-5165 | CERN 1211 Geneva 23
- | Switzerland
- -------------------------------------------------------------------------
-