0

I'm learning how to compile a C trigger to load on 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 (c.h header)

#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

I don't know how to solve that problem, because clearly that there is a working 64 bit integer datatype that I can use.

Edit: I installed pgsql from binary. The C compiler I used for compile the C function file is MinGW GCC 4.7.2. (Using the path of Dev-cpp mingw gcc).

The command line is : gcc -fpic -c "D:\trigf.c"

At the first time, it showed an error that in c.h: not found libintl.h (no such file or directory). Then I download the Lib Intl - 0.14.4 (library for native language support). The installation create a folder: C:\Program Files (x86)\GnuWin32. I edited the environment variable CPATH, added C:\Program Files (x86)\GnuWin32\include folder, which contained libintl.h.

I ran the command again, and I met with the above error.

5
  • Compile how? Exact compiler / SDK version? How are you compiling it? Compile command line / makefile / vs project file? Need more info. For what it's worth I almost always compile Windows Pg extensions by putting the extension in the contrib/ directory of a PostgreSQL source tree and using src/tools/msvc/build.pl contrib. Commented Jan 1, 2014 at 6:08
  • The HAVE_XXX macros seem to refer to an autoconf thing. Do you have config.h included before this c.h? Commented Jan 1, 2014 at 12:51
  • I've edited it. Hope you could help! Commented Jan 2, 2014 at 9:22
  • @wildplasser c.h is part of PostgreSQL's headers, btw. Very poorly named though it is. Commented Jan 5, 2014 at 1:15
  • I've written a detailed blog post explaining this now. See blog.2ndquadrant.com/… Commented Jan 11, 2014 at 8:37

1 Answer 1

1

Update: It turns out not to be too hard to build extensions stand-alone with MSVC on Windows. 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.

See these instructions on the PostgreSQL wiki.

You might be able to do it using MinGW and PGXS using a suitable Makefile instead.

Just trying to compile a standalone .c file is unlikely to work as there are a variety of paths and preprocessor definitions required.

It doesn't help that the current PostgreSQL packages don't include headers for public dependencies, which is really rather frustrating. 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Could you tell me where/what is the Pgsql build tree? I installed PostgreSQL from distributed binary for Windows x64. Do I need to download the Pqsql source and re-compile it?
@King Correct, you'd need to get the source code and follow the instructions on postgresql.org/docs/current/static/install-windows.html . (I wrote a tool github.com/2ndQuadrant/pg_build_win, that makes this process slightly easier). On non-Windows platforms all this sucks much less, you just use PGXS to compile your extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.