I've been struggling to solve a problem with a project I'm working on. Lets assume I have a few files:
reflection.h
sll_insert.c
record_sll.c
io_recorder.cpp
all of the above mentioned cpp and c files use:
#include "reflection.h"
and in "reflection.h"
are the following declarations:
extern void io_recorder_fun_entry(char * name, TypedObject args[], int len);
extern void io_recorder_fun_exit(char * name, TypedObject args[], int len);
These two functions are implemented in "io_recorder.cpp"
and they use another function from "io_recorder.cpp"
called io_record
.
now, in "io_recorder.cpp"
, the two functions are as follows:
extern "C" void io_recorder_fun_entry(char * name, TypedObject args[], int len) {
cout << "Entering function "<< name << endl;
io_record(args, len);
}
extern "C" void io_recorder_fun_exit(char * name, TypedObject args[], int len) {
cout << "Exiting function "<< name << endl;
io_record(args, len);
}
When in io_record, there are calls being made to several functions declared in reflection.h and implemented in
"record_sll.c"`.
I have 2 questions:
The connection between C and C++ is not working for me in that case (i have experimented with it previously with other files and it seemed to work before). When trying to compile I receive errors like:
io_recorder.cpp: In function ‘void io_recorder_fun_entry(char*, TypedObject*, int)’:
io_recorder.cpp:61:79: error: conflicting declaration of ‘void io_recorder_fun_entry(char*, TypedObject*, int)’ with ‘C’ linkage tern "C" void io_recorder_fun_entry(char * name, TypedObject args[], int len) {
In file included from
io_recorder.cpp:4:0: reflection.h:32:13: note: previous declaration with ‘C++’ linkage extern void io_recorder_fun_entry(char * name, TypedObject args[], int len);
Obviously I did something wrong and I can't figure out what. What am I supposed to change in order for it to compile properly?
- In previous errors, it appeared that
io_record
did not recognize the functions fromrecord_sll
when I used them. Does it have anything to do with the errors from question 1? If not, what should I do to make sureio_record
knows them.
Thanks in advance for the help, I hope i can fix this soon.