2020-06-07 08:59 AM
I would like to call C++ function from C file. How to do that.
I have C++ function call Cpp_func() in test.cpp file. In test.h file, I declare as extern "C" Cpp_func(void); This gives me error that expected identifier.
2020-06-07 09:33 AM
it needs to be declared with extern "C" in your cpp file, not your header file.
https://isocpp.org/wiki/faq/mixing-c-and-cpp#call-cpp
2020-06-07 09:36 AM
Thank you for your reply. If it is declared as extern "C" in header file. Is there a way to use this function in .c file?
2020-06-07 09:41 AM
No, it needs C linkage to be called from C.
2020-06-07 11:01 AM
Typically you'd want to create an interface function in the .CPP file with the extern "C", and then you'd call *that* function from the .C file