Mail Archives: djgpp/1998/06/16/23:29:26
On Tue, 16 Jun 1998 12:47:20 +0200, Peter Danielsson
<e96pd AT efd DOT lth DOT se> 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
- Raw text -