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:da...@artsman.com
http://www.artsman.com
Phone: (403) 536-1203 Fax: (403) 536-1210




Reply via email to