call c++ from c
Georg Fusz
fusz@ism.tu-berlin.de
Mon Mar 5 02:35:00 GMT 2001
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/
mixed.zip
--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mixed.zip
Type: application/zip
Size: 1291 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20010305/476d6551/attachment.zip>
More information about the Cygwin
mailing list