I'm writing a piece of software whose API is intended to be C only , because it is easy to link C code against other softwares/clients.
The actual program code however is done in C++, using all the usual C++ features like exception, STL, etc.
The exported API / headers themselves will be written in pure C, with the export "C"
keywords.
What should I be wary of if I intend to deliver this dll to users who have no knowledge of C++ on their side? Normally they should not be concerned about the fact that the actual code is in C++, and only be required to know how to link against C code via a header file. I've been told that I should ensure that libstd is linked statically, which may be not be possible on all platforms (there will be a linux and a windows build). How about exceptions ? etc
1) wrap your header in:
#ifdef __cplusplus
extern "C" {
#endif
2) make opaque pointers:
struct myInternalStructFOO; // incomplete type
typedef struct myInternalStructFOO *cFOO; // public type
class myInternalClassBAR; // incomplete type
typedef class myInternalClassBAR *cBAR; // public type
you need not to give class definitions in your public api. class definitions will go in some private headers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With