Mail Archives: djgpp/1996/04/12/15:28:38
Nick Burton <nmr AT doc DOT ntu DOT ac DOT uk> 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 <nicolas AT dsys DOT ceng DOT cea DOT fr>
Take a look to the SWORD home page :
http://mimine.iut.univ-metz.fr/~borysgr/sword.web/home.html
- Raw text -