编译 Windows PostgreSQL 9.5 64 位 C 语言函数
Compiling Windows PostgreSQL 9.5 64bit C-language functions
我想在 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 and Postgres Enterprise Manager Installation Guide - EnterpriseDB (PDF))
这应该可以解释为什么使用 Mingw-w64 编译的扩展会崩溃。
幸运的是,您可以选择两种解决方案:
使用Microsoft Visual Studio Community。它对个人开发者完全免费,但对企业有限制。它应该为您的 Postgresql 构建编译正确的模块。
使用 Mingw-w64 或您选择的任何其他编译器(LLVM/Clang 可能)重建完整的 Postgresql 二进制文件,然后使用相同的编译扩展。
执行其中任何一项应该对您有所帮助。这也适用于所有平台、语言和其他软件。如果您想为软件构建扩展,则需要在用于构建正在使用的软件的相同平台上使用相同的编译器。
因此,如果您想在 Linux 上为 Postgresql 构建扩展,则需要相同的编译器(可能是 GCC)来构建扩展。
编码愉快=)
@Swith 给你 link 文档 how to build PostgreSQL Extension Modules with Visual Studio 并且你可以阅读:
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.
你检查了吗?
您还可以阅读其他文档 Building PostgreSQL With MinGW - 也许这对您有更多帮助。
It would also be okay if there is another free compiler that I can use in this commercial project.
您检查过 C compliers list on wiki - in particular, you can check Cygwin 编译器了吗?上面的文档中提到了它,而且它是免费的。
I know how to get this to work with Visual Studio 2003 Express but that doesn't seem to be a solution because of License issues.
你看到什么样的问题?
也许像@Simon Mourier 建议的那样检查 Visual Studio 2015 Community Edition(不是 Express)。
Express 和 Community 版本之间的许可有很大不同 - 我不确定细节,但据我所知,Community Edition 在商业项目中使用起来更灵活:
For organizations:
An unlimited number of users within an organization can use Visual Studio Community for the following scenarios: in a classroom learning environment, for academic research, or for contributing to open source projects.
For all other usage scenarios:
In non-enterprise organizations, up to five users can use Visual Studio Community. In enterprise organizations (meaning those with >250 PCs or > Million US Dollars in annual revenue), no use is permitted beyond the open source, academic research, and classroom learning environment scenarios described above.
有关详细信息,请参阅 Visual Studio Community license terms。
我想在 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 and Postgres Enterprise Manager Installation Guide - EnterpriseDB (PDF))
这应该可以解释为什么使用 Mingw-w64 编译的扩展会崩溃。
幸运的是,您可以选择两种解决方案:
使用Microsoft Visual Studio Community。它对个人开发者完全免费,但对企业有限制。它应该为您的 Postgresql 构建编译正确的模块。
使用 Mingw-w64 或您选择的任何其他编译器(LLVM/Clang 可能)重建完整的 Postgresql 二进制文件,然后使用相同的编译扩展。
执行其中任何一项应该对您有所帮助。这也适用于所有平台、语言和其他软件。如果您想为软件构建扩展,则需要在用于构建正在使用的软件的相同平台上使用相同的编译器。
因此,如果您想在 Linux 上为 Postgresql 构建扩展,则需要相同的编译器(可能是 GCC)来构建扩展。
编码愉快=)
@Swith 给你 link 文档 how to build PostgreSQL Extension Modules with Visual Studio 并且你可以阅读:
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.
你检查了吗?
您还可以阅读其他文档 Building PostgreSQL With MinGW - 也许这对您有更多帮助。
It would also be okay if there is another free compiler that I can use in this commercial project.
您检查过 C compliers list on wiki - in particular, you can check Cygwin 编译器了吗?上面的文档中提到了它,而且它是免费的。
I know how to get this to work with Visual Studio 2003 Express but that doesn't seem to be a solution because of License issues.
你看到什么样的问题?
也许像@Simon Mourier 建议的那样检查 Visual Studio 2015 Community Edition(不是 Express)。
Express 和 Community 版本之间的许可有很大不同 - 我不确定细节,但据我所知,Community Edition 在商业项目中使用起来更灵活:
For organizations:
An unlimited number of users within an organization can use Visual Studio Community for the following scenarios: in a classroom learning environment, for academic research, or for contributing to open source projects.For all other usage scenarios:
In non-enterprise organizations, up to five users can use Visual Studio Community. In enterprise organizations (meaning those with >250 PCs or > Million US Dollars in annual revenue), no use is permitted beyond the open source, academic research, and classroom learning environment scenarios described above.
有关详细信息,请参阅 Visual Studio Community license terms。