1

Im making a iOS app and have to connect to a PostgreSQL database without web service (connect directly with the database). I started my journey from here: How to connect to postgresql from ios9

Simply, it says to follow this steps:

  1. Go find a libpq.framework.
  2. You have to create a C type file(because libpq is not Obj-c.) as C API to connect libpq.
  3. After that create a Bridging-Header to connect it.(It Bridging will not generate its own)
  4. Back to the C type file you created
  5. Follow this "PostgreSQL C Language API" tutorial this tutorial saved me a lot of time .(C has been a very far away from me.)
  6. If need, go to Build Settings >> Enable Bitcode >> YES
  7. Make sure test it on the device.

And finally, leads to this project on GitHub witch I tried to follow, but Im stuck on this error "ld: framework not found libpq"

This is what I already have done trying to make it work:

  • Download the entire project from GitHub
  • Copy the "libpq.framework" from inside the downloaded project to "MyProject/Contents/Framework/"
  • Copy "testPostgreSqlAPI.c" and "testPostgreSqlAPI.h" to my project in Xcode (Xcode made the "myProject-Bridging-Header.h" automatically)
  • Added the "libpq.framework" on "Linked Frameworks and Libraries" in the General tab on Xcode
  • Edited the Headers Search Path in the Build Settings tab to "$(PROJECT_DIR)/Contents/Frameworks/libpq.framework/Versions/A/Headers"
  • Edited the Library Search Path in the Build Settings tab to "$(PROJECT_DIR) recursive"
  • And for last, copy the "libpq.framework" to /Library/Frameworks/

After all of this, my app don't show any erro in Xcode before try to build, but when I try to build I get the error ": Linker command failed with exit code 1 (use -v to see invocation)", and in the log show the error "ld: framework not found libpq"

PS

This is my first iOS app, and my first time using Mac OS, so Im probably doing a lot of things wrong, and Im looking for any help in this context, like "Is really necessary copy the 'libpq.framework' to /Library/Frameworks/ or this ridiculous?"

1 Answers1

0

Finally after reading a lot about frameworks and shared libraries, I was able to understand why my application did not work. According to this link, "[...] You create a framework by building a normal dynamic shared library into a folder with the same name and the .framework extension. For example, to create a framework named Chaos, place a dynamic shared library named Chaos in a folder called Chaos.framework. [...] ". Looking at the framework I had downloaded, the directory structure looked like this:

libpq.framework
    |_ Versions /
        |_ A /
            |_ libpq
            |_ Headers /
                |_ libpq-fe.h
                |_ pg_config_ext.h
                |_ postgres_ext.h

So I just copied the libpq file to the same level as the Versions folder. My framework looks like this:

libpq.framework
    |_ libpq
    |_ Versions /
        |_ A /
            |_ libpq
            |_ Headers /
                |_ libpq-fe.h
                |_ pg_config_ext.h
                |_ postgres_ext.h

Now I no longer receive the error described in the title, and I can continue my tests