Hi All,
I've run into a problem and wondered if anyone could help ? I've been programming c on linux for a while now and wanted to try a little c++. Rather than do it as standalone I wanted to call c++ routines from within some existing c code. It seems that can I call the c++ functions as long as they are basically 'c' code. For example:
stuff.cc:
extern "C" {
void startingfn (void) {
printf("hello\n") ;
}
}
and...
stuff.h:
#ifndef _STARTING_H
#define _STARTING_H
extern void startingfn(void) ;
#endif
I can compile this (using gcc - defined in the makefile as used for all the c files) and call the function from my c code (with the stuff.h file included). All's fine, but if I do this:
stuff.cc:
#include <iostream.h>
extern "C" {
void startingfn (void) {
cout << "hello" << endl ;
}
}
it fails with the following message:
/.../libstarting.a(rest.o): In function `startingfn(void)':stuff.o(.text+0x4): undefined reference to `endl(ostream &)'
stuff.o(.text+0xe): undefined reference to `cout'
stuff.o(.text+0x13): undefined reference to `ostream:
perator<<(char const *)'
stuff.o(.text+0x1e): undefined reference to `ostream:
perator<<(ostream &(*)(ostream &))'
collect2: ld returned 1 exit status
make: *** [gbna] Error 1
I've tried a few variations to work around it but to no avail. I can compile the .cc file with g++ to create a working executable, but I thought this was unneccessary ?
Does the problem lie with the gcc compiler ?
Hoping for an easy solution
.