用C ++编写PostgreSQL函数 [英] Writing PostgreSQL Functions in C++

查看:119
本文介绍了用C ++编写PostgreSQL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在遵循C指南的同时用C ++编写postgres函数时遇到一些问题: C语言功能。我发现大多数postgres函数都是用C而不是C ++编写的,但是我必须使用用C ++编写的库,因此我选择了C ++。我的问题是,用C ++编写时有什么要注意的吗?使用pgxs编写makefile是很常见的,那么我应该如何编写makefile使其起作用?谢谢。

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.

推荐答案

如果可以避免这样做,请这样做。 PostgreSQL与C ++结合得不是很好。可能是,如PostGIS所示,但这并不是太有趣。

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.

如果可以的话,请为您的C ++编写或生成一个纯C包装器库并使用该包装器与库进行交互。如果它是基于模板的(例如,boost)或使用其他更高级的C ++功能,那将是不切实际的,但如果仅是带有对象的C样式代码,则效果很好。 SWIG可以帮助您生成包装器。

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.

如果您希望避免使用包装器方法,或者您的库过于复杂,过于依赖异常,等等。那么您应该阅读此PostgreSQL手册条目

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.

搜索PostgreSQL邮件列表以获取有关此主题的更多讨论。

Search the PostgreSQL mailing list for more discussion on this topic.

这篇关于用C ++编写PostgreSQL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆