views:

157

answers:

2

Hi,

I'm trying to use libpq, the client library for PostgreSQL in a Cocoa app.

First thing, adding the header files: I tried adding the path to the PostgreSQL header files under User Header Search Path on my project's properties and then compile but for some reason XCode can't see them. The solution was to manually add the files and a copy of libpq.a to the project.

This worked, but now when I build I get an SSL error:

"_SSL_CTX_set_client_cert_cb", referenced from:
_pqsecure_initialize in libpq.a(fe-secure.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status

Some research shows that this is because there's a mismatch between the SSL headers and the SSL libraries. How can I find the right header files?

A: 

Adding to the header search path doesn't automatically include files in your code; you still need to use #include or #import. If you did that, you can expand the build results to see the exact compiler/linker commands Xcode is generating; it should give you some idea of what's going wrong.

Just compile the PostgreSQL client libraries yourself, that way you know what SSL libraries you're compiling against, and can include them if they're not part of OS X.

Nicholas Riley
I've done both: added the search path to my project settings and I'm #importing <libpq-fe.h>.I can see the file on the directory I added using Finder, I just can't make XCode search that particular path.
Rui Pacheco
Try pasting your compile output somewhere then (do a clean first so we get all of it)... perhaps something will jump out.
Nicholas Riley
A: 

I think I solved this, but it still needs to be tested further:

First, I created a link to the postgresql library that was installed with the database server:

sudo ln -s /opt/local/lib/postgresql80/libpq.dylib /usr/lib/libpq.dylib

I then removed the reference to libpq.a from the project and linked it against the new postgresql .dylib. This immediately solved my SSL problem.

I still can't make XCode see the postgresql header files, but at least that's solved by including them manually on the project with no apparent problems.

Rui Pacheco
Aiee, don't link or otherwise write into `/usr`, that's a bad idea. You should be able to get it to work the right way; there's nothing abnormal about what you're trying to do.
Nicholas Riley
Hmmm, it does seem to produce strange bugs. It compiled once but now fails on the linkage. Maybe if I add the path to the postgresql library to the project settings...(this is a very frustrating problem)
Rui Pacheco
Ok, fixed it by (very carefully) rm'ing the simlink under /usr and adding the path to the library to the project settings by doing this:Project -> Project Settings -> Build -> Library Search Paths and then adding the path to the library.I've cleaned and compiled several times and seems to work well.
Rui Pacheco