Path: utzoo!utgpu!watserv1!watmath!att!occrsh!uokmax!apple!julius.cs.uiuc.edu!wuarchive!zaphod.mps.ohio-state.edu!samsung!uunet!sjsca4!poffen From: poffen@sj.ate.slb.com (Russ Poffenberger) Newsgroups: comp.lang.c++ Subject: Re: C/C++ link in TC++ Message-ID: <1990Sep11.165053.24745@sj.ate.slb.com> Date: 11 Sep 90 16:50:53 GMT References: <4800101@m.cs.uiuc.edu> Reply-To: poffen@sj.ate.slb.com (Russ Poffenberger) Organization: Schlumberger Technologies, San Jose, CA. Lines: 64 In article <4800101@m.cs.uiuc.edu> reed@m.cs.uiuc.edu writes: > > >I've been trying to link C object modules with C++, both created >using Turbo C++. I must be doing something stupid, because the >Turbo linker is unable to find the C reference. I've attached a >code sample below that fails when I do the following: > > tcc -c y.c > tcc -c x.cpp y.obj > >This fails to resolve the reference to "try" > >Any ideas on what I'm overlooking? > >Thanks in advance, > >Dan Reed reed@cs.uiuc.edu >Associated Professor >Department of Computer Science >University of Illinois >================================ y.c ========================= >#include > >void try (int x) >{ > printf ("Value is %d\n", x); >} >================================ x.cpp ======================= >#include > >extern void try(int x); > >main() >{ > int y; > > cout <<"Before call\n"; > > y = 10; > try (y); > > cout<<"After call\n"; >} >========= end of x.cpp ========== Try this in your c++ program... extern "C" { void try(int); } as your function prototype in x.cpp. The problem is with naming conventions. C++ uses new internal naming conventions so it can distinguish between instances of overloaded functions and such. Using the above syntax forces the compiler to use standard C naming conventions. Russ Poffenberger DOMAIN: poffen@sj.ate.slb.com Schlumberger Technologies UUCP: {uunet,decwrl,amdahl}!sjsca4!poffen 1601 Technology Drive CIS: 72401,276 San Jose, Ca. 95110 (408)437-5254