1

For a shared library project written in C, if I rewrite part of the code in C++, but exactly the same APIs is kept, will I have any ABI compatibility issues?

xuhdev
  • 8,018
  • 2
  • 41
  • 69
  • 1
    This depends on the compiler, but at the least, you will probably need to use an [extern "C"](http://en.cppreference.com/w/cpp/language/language_linkage) specifier. – Mankarse Jun 27 '14 at 05:16

1 Answers1

4

If you keep the same API (function names and parameter types) you should be good to go.

What you will need to do is wrap your header files with this (copy & pasted from here):

#ifdef __cplusplus
extern "C" {
#endif

// all of your legacy C code here

#ifdef __cplusplus
}
#endif

This makes sure that the C++ compiler doesn't mangle those names, so the C compiler's extern symbols can still be linked against the exports.

Community
  • 1
  • 1
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328