From: jlrubin AT bway DOT net (Josh Rubin) Newsgroups: comp.os.msdos.djgpp Subject: Re: Help! I cant link c-source with c++-source Date: Tue, 16 Jun 1998 14:52:25 GMT Organization: ISPNews http://ispnews.com Lines: 37 Message-ID: <35868313.1231088@news1.bway.net> References: <35864D37 DOT 69F2 AT efd DOT lth DOT se> NNTP-Posting-Host: dial-iris-34.bway.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Date: 16 Jun 1998 14:52:29 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Tue, 16 Jun 1998 12:47:20 +0200, Peter Danielsson wrote: >I'm using allegro and it is c. I'm more used to c++, so i tried to have >the mainprogram in one file with the extension .c and wanted to call my >functions in a .cpp-file. The gcc-compilation works good, but when >linking it cant find my functions in the .cpp-file. What must I do to >link two different sources? You must tell the C++ compiler which functions were compiled as C. Otherwise it does name mangling, and the linker will fail to find the C definition. This is standard C++, and should be described in a good book. In file main.cc: extern "C" { struct mystruct { ... }; // declare types used to communicate // between C and C++. int func(int x); // declare functions compiled as C } in file.c : int func(int x) // no special declarations { .... } You can get fancy and write a header file that puts in the extern "C" when compiled as C++ and omits it when compiled as C. Josh Rubin jlrubin AT bway DOT net