Erklær dine funktioner som extern "C":
/* testpp.cpp */
#include <iostream>
using std::cout;
using std::endl;
extern "C" int write_stuff() {
cout << "Hello, World!" << endl;
return 0;
}
/* testc.c */
int write_stuff();
int main (int argc, char ** argv) {
write_stuff();
return 0;
}
Compiling og kørsel:
$ g++ -c -o testpp.o testpp.cpp
$ gcc -c -o testc.o testc.c
$ g++ -o test testc.o testpp.o
$ ./test
Hello, World!
$