I have some problem writing postgres functions in C++ while following the guides for C: C-Language Functions. I found that most postgres functions are written in C instead C++, but I have to use a lib that is written in C++, so I chose C++. My question is, is there anything to notice when writing in C++? It's common to write makefiles using pgxs, so how should I write the makefile to make it work? Thanks.
If you can avoid doing it, do so. PostgreSQL doesn't mix especially well with C++. It's possible, as shown by PostGIS, but it's not overly fun.
If you can, write or generate a pure C wrapper to your C++ library and use that wrapper to interact with the library. That won't be practical if it's heavily template based (eg: boost) or uses other more advanced C++ features, but works well if it's just C-with-objects style code. SWIG can help generate wrappers for you.
If you'd prefer to avoid the wrapper approach or if your library is a bit too complex, too exception-reliant, etc for that then you should read this PostgreSQL manual entry.
Search the PostgreSQL mailing list for more discussion on this topic.
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