Xref: news2.mv.net comp.os.msdos.djgpp:2649 From: nicolas AT dsys DOT ceng DOT cea DOT fr (Eric NICOLAS) Newsgroups: comp.os.msdos.djgpp Subject: Re: MikMod210 [Linking C and C++ together] Date: 11 Apr 1996 06:54:54 GMT Organization: Commissariat a l'energie atomique Grenoble (France) Lines: 62 Message-ID: <4kiabu$evf@news.cea.fr> References: <199604090947 DOT FAA22372 AT delorie DOT com> Reply-To: nicolas AT dsys DOT ceng DOT cea DOT fr NNTP-Posting-Host: hudson.ceng.cea.fr To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Nick Burton writes: >Ok I have this great program (mikmod) which I can make and >run fine under GNU C Ver 2.x, when its linked to my code. > >But when I try to link it to some of my GNU C++ Ver 2.x >code make complains at the linking stage that it cant find >any of the mikmod funcs? > Your problem is probably to link C code and C++ code together. In C code, functions are exported using their names with an underscore before. For example prinf is exported as _printf. In C++, functions are exported using their names plus characters that tell what the args are. So if you try to link C and C++ together, that won't work because #include files of your C code will be parsed with the C++ function names and those names will not be found in the previously C-compiled ..o. The solution is to tell the compiler to generate old-C names for C-code even if the compilation is in C++ mode. Here how to do that : Begin ALL your C-code include files with (let say myinclude.h) : -------------- #ifndef _MYINCLUDE_H_ #define _MYINCLUDE_H_ #ifdef __cplusplus extern "C" { #endif -------------- And finish your C-code include files with : --------------- #ifdef __cplusplus } #endif #endif --------------- So, when you use those include files as C-code, nothing special happens, BUT when you use those include files in C++ code, they will be delimited by extern "C" { ... } So old-C function names will be generated. Hope it helps. -- Eric Nicolas Take a look to the SWORD home page : http://mimine.iut.univ-metz.fr/~borysgr/sword.web/home.html