I\'m using Linux and I have the following files:
main.c, main.h
fileA.c, fileA.h
fileB.cpp, fileB.h
The function F1()
is decla
If you're really compiling fileA.c
as C, not C++, then you need to make sure that the function has the proper, C-compatible linkage.
You can do this with a special case of the extern
keyword. Both at declaration and definition:
extern "C" void F1();
extern "C" void F1() {}
Otherwise the C linker will be looking for a function that only really exists with some mangled C++ name, and an unsupported calling convention. :)
Unfortunately, whilst this is what you have to do in C++, the syntax isn't valid in C. You must make the extern
visible only to the C++ code.
So, with some preprocessor magic:
#ifdef __cplusplus
extern "C"
#endif
void F1();
Not entirely pretty, but it's the price you pay for sharing a header between code of two languages.