简体   繁体   English

PostgreSQL:在Windows 8 64bit上编译C函数

[英]PostgreSQL: compile C function on Windows 8 64bit

I'm learning how to compile a C trigger to load on PostgreSQL 我正在学习如何编译C触发器以在PostgreSQL上加载

When compile the "trigf.c" (in the example at http://www.postgresql.org/docs/9.3/interactive/trigger-example.html ), I get some issue related to int64 error (ch header) 当编译“ trigf.c”时(在http://www.postgresql.org/docs/9.3/interactive/trigger-example.html的示例中),我得到一些与int64错误(ch标头)有关的问题

#ifdef HAVE_LONG_INT_64
/* Plain "long int" fits, use it */

#ifndef HAVE_INT64
typedef long int int64;
#endif
#ifndef HAVE_UINT64
typedef unsigned long int uint64;
#endif
#elif defined(HAVE_LONG_LONG_INT_64)
/* We have working support for "long long int", use that */

#ifndef HAVE_INT64
typedef long long int int64;
#endif
#ifndef HAVE_UINT64
typedef unsigned long long int uint64;
#endif
#else
/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
#error must have a working 64-bit integer datatype
#endif

-> [Error] #error must have a working 64-bit integer datatype -> [错误] #error必须具有有效的64位整数数据类型

I don't know how to solve that problem, because clearly that there is a working 64 bit integer datatype that I can use. 我不知道如何解决该问题,因为显然我可以使用一个有效的64位整数数据类型。

Edit: I installed pgsql from binary. 编辑:我从二进制安装pgsql。 The C compiler I used for compile the C function file is MinGW GCC 4.7.2. 我用于编译C函数文件的C编译器是MinGW GCC 4.7.2。 (Using the path of Dev-cpp mingw gcc). (使用Dev-cpp mingw gcc的路径)。

The command line is : gcc -fpic -c "D:\\trigf.c" 命令行是:gcc -fpic -c“ D:\\ trigf.c”

At the first time, it showed an error that in ch: not found libintl.h (no such file or directory). 第一次,它在ch中显示一个错误:找不到libintl.h(没有这样的文件或目录)。 Then I download the Lib Intl - 0.14.4 (library for native language support). 然后,我下载了Lib Intl-0.14.4(支持本地语言的库)。 The installation create a folder: C:\\Program Files (x86)\\GnuWin32. 安装将创建一个文件夹:C:\\ Program Files(x86)\\ GnuWin32。 I edited the environment variable CPATH, added C:\\Program Files (x86)\\GnuWin32\\include folder, which contained libintl.h. 我编辑了环境变量CPATH,添加了包含libintl.h的C:\\ Program Files(x86)\\ GnuWin32 \\ include文件夹。

I ran the command again, and I met with the above error. 我再次运行了命令,遇到了上面的错误。

Update : It turns out not to be too hard to build extensions stand-alone with MSVC on Windows. 更新 :事实证明,在Windows上使用MSVC独立构建扩展不是太难。 I wrote a blog post detailing the process today . 写了一篇博客文章,详细介绍了今天的过程


The usual way to build extensions on Windows is to do it inside a working PostgreSQL build tree. 在Windows上构建扩展的通常方法是在工作的PostgreSQL构建树中进行扩展。

See these instructions on the PostgreSQL wiki . 请参阅PostgreSQL Wiki上的这些说明

You might be able to do it using MinGW and PGXS using a suitable Makefile instead. 您也许可以使用MinGW和PGXS并使用合适的Makefile来做到这一点。

Just trying to compile a standalone .c file is unlikely to work as there are a variety of paths and preprocessor definitions required. 仅尝试编译独立的.c文件不太可能起作用,因为需要各种路径和预处理器定义。

It doesn't help that the current PostgreSQL packages don't include headers for public dependencies, which is really rather frustrating. 当前的PostgreSQL软件包不包含公共依赖的头文件并没有帮助,这确实令人沮丧。 You can safely compile without ENABLE_NLS defined even if the target PostgreSQL was built with ENABLE_NLS , though, and in this case libintl.h won't be required. 即使目标PostgreSQL是使用ENABLE_NLS构建的,您也可以在没有定义ENABLE_NLS情况下安全地进行编译,在这种情况下, libintl.h

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

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