简体   繁体   English

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

[英]Compiling Windows PostgreSQL 9.5 64bit C-language functions

I want to create native C extensions to PostgreSQL 9.5 64bit on Windows. 我想在Windows上为PostgreSQL 9.5 64位创建本机C扩展。

I would love to build them with MinGW-w64 if that's possible, to get my build chain as clean as possible. 我希望用MinGW-w64构建它们,如果可能的话,让我的构建链尽可能干净。 But I am using the EnterpriseDB build of PostgreSQL, and MinGW build crashes it. 但我使用的是PostgreSQL的EnterpriseDB版本,而MinGW版本则崩溃了。

It would also be okay if there is another free compiler that I can use in this commercial project. 如果我可以在这个商业项目中使用另一个免费的编译器也没关系。

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. 我知道如何使用Visual Studio 2003 Express,但由于许可证问题,这似乎不是一个解决方案。

Addition to the Main Answer 除主要答案外

In the article linked below , you can read that it is possible to write C modules using Mingw or Cygwin, and some guidelines regarding the same. 下面链接文章中 ,您可以读到可以使用Mingw或Cygwin编写C模块,以及一些有关相同的指南。 However I highly discourage doing so, mostly because of the reasons listed below, and also because that page mentions that those Windows configurations have special needs and receive lighter testing than most; 但是我强烈反对这样做,主要是因为下面列出的原因,并且因为该页面提到那些Windows配置有特殊需求并且接受比大多数更轻的测试; expect a greater incidence of build problems 期望更多的构建问题发生

Here is the full excerpt on Unix-like Platform: 以下是类Unix平台的完整摘录:

Unix-like Platforms 类Unix的平台

PGXS originated on Unix-like systems, and it is easy to use there. PGXS起源于类Unix系统,在那里很容易使用。 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. 如果在shell中运行类型pg_config找到正确的PostgreSQL安装,则可以省略PG_CONFIG覆盖。 Subject to the ownership of the existing PostgreSQL installation directories, the second command will often require root privileges. 根据现有PostgreSQL安装目录的所有权,第二个命令通常需要root权限。 These instructions also apply when building for Windows using the MinGW or Cygwin compilers. 使用MinGW或Cygwin编译器为Windows构建时,这些说明也适用。 However, those Windows configurations have special needs and receive lighter testing than most; 但是,这些Windows配置有特殊需求,并且接收的测试比大多数情况要轻; 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. 一个常见的错误是在'make'之前在命令行上指定PG_CONFIG = ...,这不起作用,因为该值随后被makefile的内部工作方式覆盖。


It's important to know that different compilers are not compatible with each other. 重要的是要知道不同的编译器彼此不兼容。 Each of them have different runtime libraries. 它们每个都有不同的运行时库。 So it is very risky to compile extensions with a different compiler other than the one used to build the software you are using. 因此,除了用于构建您正在使用的软件的编译器之外,使用不同的编译器编译扩展是非常危险的。

Postgresql's Windows build uses Visual Studio, same with EnterpriseDB (as far as I know). Postgresql的Windows构建使用Visual Studio,与EnterpriseDB相同(据我所知)。 You will need to use the same compiler to build your extensions. 您将需要使用相同的编译器来构建扩展。

(For more information please refer: Building and Installing PostgreSQL Extension Modules and Postgres Enterprise Manager Installation Guide - EnterpriseDB (PDF) ) (有关更多信息,请参阅: 构建和安装PostgreSQL扩展模块Postgres Enterprise Manager安装指南 - EnterpriseDB(PDF)

This should explain why your extensions compiled with Mingw-w64 crash. 这可以解释为什么使用Mingw-w64编译的扩展崩溃。

Luckily, there are two solutions you could choose: 幸运的是,您可以选择两种解决方案:

  1. Use Microsoft Visual Studio Community . 使用Microsoft Visual Studio社区 It is completely free for individual developers, however there are restrictions for businesses. 对于个人开发者来说完全免费,但对企业有限制。 It should compile proper modules for your Postgresql build. 它应该为Postgresql构建编译适当的模块。

  2. Rebuild the compleat Postgresql binary with Mingw-w64 or any other compiler of your choice (LLVM/Clang maybe), and then compile extensions with the same. 使用Mingw-w64或您选择的任何其他编译器(可能是LLVM / Clang)重建完整的Postgresql二进制文件,然后使用相同的编译扩展。

Doing either of these should help you. 做其中任何一项都可以帮到你。 And this applies to all platforms, languages, and other softwares too. 这也适用于所有平台,语言和其他软件。 If you want to build extensions for a software, you need the same compiler, on the same platform used to build the software being used. 如果要为软件构建扩展,则需要在用于构建所用软件的同一平台上使用相同的编译器。

So, if you want to build extensions for Postgresql on Linux, you need the same compiler (probably GCC) to build extensions. 因此,如果您想在Linux上为Postgresql构建扩展,则需要相同的编译器(可能是GCC)来构建扩展。

Happy coding =) 快乐编码=)

@Swith give you link to docs how to build PostgreSQL Extension Modules with Visual Studio and as you can read: @Swith为您提供了如何使用Visual Studio构建PostgreSQL扩展模块的文档链接,您可以阅读:

These instructions also apply when building for Windows using the MinGW or Cygwin compilers. 使用MinGWCygwin编译器为Windows构建时,这些说明也适用。 However, those Windows configurations have special needs and receive lighter testing than most; 但是,这些Windows配置有特殊需求,并且接收的测试比大多数情况要轻; 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. 一个常见的错误是在'make'之前在命令行上指定PG_CONFIG = ...,这不起作用,因为该值随后被makefile的内部工作方式覆盖。

Did you check this ? 你看了吗?

Also you can read other docs Building PostgreSQL With MinGW - maybe this help you more. 您也可以阅读其他文档使用MinGW构建PostgreSQL - 也许这会对您有所帮助。



It would also be okay if there is another free compiler that I can use in this commercial project. 如果我可以在这个商业项目中使用另一个免费的编译器也没关系。

Did you check C compliers list on wiki - in particular, you can check Cygwin compiler - it's mentioned in docs above and it's free. 您是否在wiki上检查了C compliers列表 - 特别是,您可以检查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. 我知道如何使用Visual Studio 2003 Express,但由于许可证问题,这似乎不是一个解决方案。

What kind of issues do you see ? 你看到了什么样的问题?


Maybe check Visual Studio 2015 Community Edition (not Express) like @Simon Mourier suggest. 也许请查看@Simon Mourier建议的Visual Studio 2015社区版 (不是Express)。

There is quite different licencing between Express and Community editions - I'm not sure about details, but as far I know Community Edition is more flexible for using in commercial projects: 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. 组织中的无限数量的用户可以将Visual Studio社区用于以下场景:在课堂学习环境中,用于学术研究,或用于开源项目。

For all other usage scenarios: 对于所有其他使用场景:
In non-enterprise organizations, up to five users can use Visual Studio Community. 在非企业组织中,最多五个用户可以使用Visual Studio社区。 In enterprise organizations (meaning those with >250 PCs or >$1 Million US Dollars in annual revenue), no use is permitted beyond the open source, academic research, and classroom learning environment scenarios described above. 在企业组织中(意味着那些拥有超过250台个人电脑或年收入超过100万美元的企业),除了上述开源,学术研究和课堂学习环境之外,不允许使用它们。

For more information, see the Visual Studio Community license terms . 有关详细信息,请参阅Visual Studio社区许可条款

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM