简体   繁体   中英

Linking to PostgreSQL and SSL

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM