home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!not-for-mail
- From: ren@function.mps.ohio-state.edu (Liming Ren)
- Newsgroups: comp.lang.c++
- Subject: Re: How to call C++ functions in a C program?
- Date: 17 Dec 1992 15:30:02 -0500
- Organization: Department of Mathematics, The Ohio State University
- Lines: 32
- Message-ID: <1gqo0aINN5jj@function.mps.ohio-state.edu>
- References: <1gqbepINNt6s@function.mps.ohio-state.edu> <1gqe3lINNs1v@eagle.natinst.com> <SCHOUTEN.92Dec17125550@sp95.csrd.uiuc.edu>
- NNTP-Posting-Host: function.mps.ohio-state.edu
-
- First, I want to thank all those very knowledge people who responsed to my
- question. Some said yes and others saied no. I read all the resopnse carefully.
- It seems to me the answer is somewhere in between. Is that true that for a C++
- function to be callable in a C program, it must be written in C style? I tried:
-
- foo.c:
-
- #include<iostream.h>
- //callable from C
- extern "C" int callable_from_c (int i)
- {
- cout<<"Merry Chrismas"<<endl;
- return i;
- }
-
-
- CC -c foo.c turns out all right!
-
- When I call this function in a C program, I get error message as:
-
- ld: Undefined symbol
- _cout
- _endl__FR7ostream
- ___ls__7ostreamFPCc
- ___ct__13Iostream_initFv
- ___dt__13Iostream_initFv
-
- But if I erase the #include<iostream.h> line and the cout line,
- everything turns out to be all right.
-
- Merry Chrismas!
-
-