This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

call c++ from c


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

------------------------------------------------------------

//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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]