修复库兼容性c++ mingw和postgresql

Fixing lib compatibility c++ mingw and postgresql

本文关键字:mingw postgresql c++ 兼容性      更新时间:2023-10-16

我正在尝试将postgresql与SOCI一起使用,使用MinGW构建他们的库。

我遇到了下面的问题。

PostgreSQL定义了这个结构@ pthread.h:
#ifndef HAVE_STRUCT_TIMESPEC
#define HAVE_STRUCT_TIMESPEC 1
struct timespec {
    long tv_sec;
    long tv_nsec;
};
#endif /* HAVE_STRUCT_TIMESPEC */

但是在编译器中,还有这个结构@ 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

这会导致重复的timespec声明。我的问题是:

  • 我可以在postgresql编辑宏来避免这被声明两次吗?
  • 如果是,那么time_t长的时间差。tv_spec的类型是一个问题?
  • 解决这种情况的好方法是什么?

使用PostgreSQL 9.3 x86

time_tlong 可能是一个问题,尽管我发现它不太可能。这是因为time_t通常被定义为long的别名。

代替改变postgres库中的宏,我将首先尝试定义传递-D标志给编译器的宏。

g++ -DHAVE_STRUCT_TIMESPEC -o prog file.cc