Subject: Re: call c++ from c
From: Georg Fusz <[email-masked]>
To: Trace Young <[email-masked]>
Cc: [email-masked]
Date: Mon, 05 Mar 2001 10:35:25 +0000

Trace Young wrote:
> 
> Hi, is anybody could help me to point out the problem:
> 
> my problems is: it could not link while calling a c++ function in
> cpp file from c function in c file with the main().
> 
> both c and cpp files can be compiler in VC++ in NT4.0, but not link
> the link error message is "unresolved external symbol _cpp_function".
> ( but I could do those in GUN g++ in Uuix )
> 
> following is my code
> ------------------------------------------------------------------
> /*c_file.c*/
> #include "c_file.h"
> int main(){
>   cpp_function();
>   return(0);
> }
> 
> ----------------------------------------------------------
> 
> /*c_file.h*/
> #ifndef __cplusplus
> extern "C++" {
> #endif
> 
> #include "cpp_file.h"
> 
> #ifndef __cplusplus
> }
> #endif
> 
> 

Here is your mistake !!!!!!!!!!!!!!!!!!!!!

#ifdef __cplusplus
extern "C" {
#endif

void cpp_function( void );
    
#ifdef __cplusplus
}
#endif
------------------------------------------------------------
> 
> //cpp_file.cpp
> #include "cpp_file.h"
> #include <iostream>
> /*
> foo::foo() {
>   i=0;
> }
> */
> void cpp_function(){
>   foo f;
> 
>   f.see();
>   cout<<"Hi, I am in Cpp file and called by C file\n"<<flush;
> }
> 
> ---------------------------------------------------------------------
> 
> //cpp_file.h
> #include <iostream.h>
> 
> class foo {
> public:
>   int i;
> 
>   foo() {i=0; }
>   ~foo() {}
> 
>   void see() {
>     cout << "--------------I am inside class ------------" << endl;
>   }
> 
> };
> 
> void cpp_function();
> ------------------------------------------------------------------------------------
> 
> Thank for any help.
> 
>         Trace
> 
> --
> Want to unsubscribe from this list?
> Check out: http://cygwin.com/ml/#unsubscribe-simple

-- 
Georg Fusz
Technische Universitaet Berlin, Germany

Fon:
Uni.: +49 30 314 26 884
privat: +49 30 815 30 32
Handy: +49 173 20 10 696

Homepage: http://www.cadlab.tu-berlin.de/~fusz/

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple