加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

编译Windows PostgreSQL 9.5 64位C语言函数

发布时间:2020-12-14 04:00:22 所属栏目:Windows 来源:网络整理
导读:我想在 Windows上为PostgreSQL 9.5 64位创建本机C扩展. 我希望用MinGW-w64构建它们,如果可能的话,让我的构建链尽可能干净.但我使用的是PostgreSQL的EnterpriseDB版本,而MinGW版本则崩溃了. 如果我可以在这个商业项目中使用另一个免费的编译器也没关系. 我知
我想在 Windows上为PostgreSQL 9.5 64位创建本机C扩展.

我希望用MinGW-w64构建它们,如果可能的话,让我的构建链尽可能干净.但我使用的是PostgreSQL的EnterpriseDB版本,而MinGW版本则崩溃了.

如果我可以在这个商业项目中使用另一个免费的编译器也没关系.

我知道如何使用Visual Studio 2003 Express,但由于许可证问题,这似乎不是一个解决方案.

解决方法

除主要答案外

在article linked below中,您可以读到可以使用Mingw或Cygwin编写C模块,以及一些有关相同的指南.但是我强烈反对这样做,主要是因为下面列出的原因,并且因为该页面提到那些Windows配置有特殊需求并且接受比大多数更轻的测试;期望更多的构建问题发生

以下是类Unix平台的完整摘录:

Unix-like Platforms

PGXS originated on Unix-like systems,and it is easy to use there. Unpack the extension module archive and run these commands in the resulting directory:

make PG_CONFIG=path_to_postgresql_installation/bin/pg_config
make PG_CONFIG=path_to_postgresql_installation/bin/pg_config install

You may omit the PG_CONFIG overrides if running type pg_config in your shell locates the correct PostgreSQL installation. Subject to the ownership of the existing PostgreSQL installation directories,the second command will often require root privileges. These instructions also apply when building for Windows using the MinGW or Cygwin compilers. However,those Windows configurations have special needs and receive lighter testing than most; expect a greater incidence of build problems.

A common mistake is to specify the PG_CONFIG=… on the command line before the ‘make’,which does not work as the value is then overridden by the inner workings of makefiles.

重要的是要知道不同的编译器彼此不兼容.它们每个都有不同的运行时库.因此,除了用于构建您正在使用的软件的编译器之外,使用不同的编译器编译扩展是非常危险的.

Postgresql的Windows构建使用Visual Studio,与EnterpriseDB相同(据我所知).您将需要使用相同的编译器来构建扩展.

(欲了解更多信息,请参阅:Building and Installing PostgreSQL Extension Modules和Postgres Enterprise Manager Installation Guide – EnterpriseDB (PDF))

这可以解释为什么使用Mingw-w64编译的扩展崩溃.

幸运的是,您可以选择两种解决方案:

>使用Microsoft Visual Studio Community.个人开发者完全免费,但对企业有限制.它应该为Postgresql构建编译适当的模块.
>使用Mingw-w64或您选择的任何其他编译器(可能是LLVM / Clang)重建完整的Postgresql二进制文件,然后使用相同的编译扩展.

做其中任何一项都可以帮到你.这也适用于所有平台,语言和其他软件.如果要为软件构建扩展,则需要在用于构建所用软件的同一平台上使用相同的编译器.

因此,如果您想在Linux上为Postgresql构建扩展,则需要相同的编译器(可能是GCC)来构建扩展.

快乐编码=)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读