Search code examples
c++postgresqlmingwsoci

Fixing lib compatibility c++ mingw and postgresql


I am trying to use postgresql together with SOCI, building their libs with MinGW.

I ran into the following problem.

PostgreSQL defines this strcuture @ pthread.h:

#ifndef HAVE_STRUCT_TIMESPEC
#define HAVE_STRUCT_TIMESPEC 1
struct timespec {
    long tv_sec;
    long tv_nsec;
};
#endif /* HAVE_STRUCT_TIMESPEC */

But into the compiler, there is also this structure @ timeb.h

#ifndef _TIMESPEC_DEFINED
#define _TIMESPEC_DEFINED
struct timespec {
    time_t  tv_sec;   /* Seconds */
    long    tv_nsec;  /* Nanoseconds */
};

struct itimerspec {
    struct timespec  it_interval;  /* Timer period */
    struct timespec  it_value;     /* Timer expiration */
};
#endif

This is causing duplicate declaration of timespec. My questions are:

  • Can I just edit the macros at postgresql to avoid this to be declared twice?
  • If so, would this time_t and long difference of timespec.tv_spec's type be a problem?
  • What would be a good way to fix this situation?

I am using PostgreSQL 9.3 x86


Solution

  • time_t and long could be a problem, although I find it very unlikely. This is because time_t is usually defined as an alias to a long.

    Instead of changing the macros in postgres' libraries, I would first try to define the macro passing -D flag to the compiler.

    g++ -DHAVE_STRUCT_TIMESPEC -o prog file.cc