Mac OS X 10.6 - libpq.dylib vs. libpq.a and PQisthreadsafe()

From: David McKeone <david(at)artsman(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Mac OS X 10.6 - libpq.dylib vs. libpq.a and PQisthreadsafe()
Date: 2011-10-17 13:53:08
Message-ID: 5F5D5EB5-3408-4452-802E-A8CF718AAC7D@artsman.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I've been getting acquainted with the C interface for libpq and have run into an issue with trying to link to the dynamic libpq while still getting thread safety. I have tried the following by compiling the 9.1 source with the --enable-thread-safety flag and I've tried the libpq libraries provided in the EnterpriseDB build of 9.1. All of this is on Mac OS X 10.6.8 with XCode 4.0.2.

The problem I'm having is that PQisthreadsafe() returns 0 when I link to the dynamic library(libpq.5.4.dylib), but it returns 1 when I link to the static library (libpq.a). The code I'm using is as follows:

#include "libpq-fe.h"

int main (int argc, const char * argv[])
{
if (PQisthreadsafe() == 1) {
puts("Thread safe");
} else {
puts("Not thread safe");
}
}

Commands and output (main.c, libpq.a and libpq.5.4.dylib are all in the same directory):

gcc -I /Library/PostgreSQL/9.1/include main.c libpq.a -o main

Output: "Thread safe"

gcc -I /Library/PostgreSQL/9.1/include main.c libpq.5.4.dylib -o main

Output: "Not thread safe"

I'm admittedly not great with the nuances of the linker or with the PostgreSQL C interface so it's possible I'm missing something obvious here. If anyone knows how I should be using libpq as a dynamic library with thread safety, then that would be a great help.

Regards,
__________________________________
David McKeone
Arts Management Systems Ltd.
mailto:david(at)artsman(dot)com
http://www.artsman.com
Phone: (403) 536-1203 Fax: (403) 536-1210

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2011-10-17 14:24:13 Re: plpgsql; execute query inside exists
Previous Message Alban Hertroys 2011-10-17 13:44:24 Re: plpgsql; execute query inside exists