• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Linking against a re-exported library
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linking against a re-exported library


  • Subject: Linking against a re-exported library
  • From: Kyle Sluder <email@hidden>
  • Date: Tue, 31 Dec 2013 01:08:00 -0800

Hi all,

I'm trying to wrap up the PostgreSQL client libraries into a framework
so we can embed it in an internal Mac application. This approach is
preferable to dropping dylibs in every employee's /Library as we can
keep distributing the app as a drag-and-drop installation (and it also
makes the development process a lot smoother too).

So I've got a couple of libraries from a distribution of PostgreSQL for
OS X: libpq.5.6.dylib (the main client library), plus libssl.1.0.0.dylib
and libcrypto.1.0.0.dylib, which are necessary because they don't offer
binary compatibility between point releases (and therefore I can't just
link against the system's versions of these libraries).

The install name for libpq.5.6.dylib is actually "libpq.5.dylib", and it
is configured to look for libssl and libcrypto in "@loader_path/../lib".
Since I can't seem to change libpq's install name, I'm copying all three
dylibs to a "lib" subdirectory in the framework wrapper, and using a Run
Script build phase to generate a wrapper PostgreSQL.dylib that
re-exports the symbols from libpq:

#--snip--
EXECUTABLE_PATH="$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH/$EXECUTABLE_NAME"
ld -dylib -arch "$CURRENT_ARCH" -reexport_library
"$TARGET_BUILD_DIR/$WRAPPER_NAME/lib/libpq.5.6.dylib" -o
"$EXECUTABLE_PATH" -install_name "$LD_DYLIB_INSTALL_NAME"
#--snip--

This results in a framework with the following structure:

PostgreSQL.framework/
 Versions/
   A/
     PostgreSQL
     lib/
       libpq.5.6.dylib
       libssl.1.0.0.dylib
       libcrypto.1.0.0.dylib

Then, because libpq's install name was just plain "libpq.5.dylib" at the
time my ld command created the wrapper dylib, my Run Script phase needs
to patch up the wrapper dylib's load commands:

#--snip--
install_name_tool -change "libpq.5.dylib"
"@rpath/$CONTENTS_FOLDER_PATH/lib/libpq.5.6.dylib" "$EXECUTABLE_PATH"
#--snip--

otool shows the result:

% otool -L PostgreSQL.framework/Versions/A/PostgreSQL
PostgreSQL.framework/Versions/A/PostgreSQL:
   @rpath/PostgreSQL.framework/Versions/A/PostgreSQL (compatibility
   version 0.0.0, current version 0.0.0)
   @rpath/PostgreSQL.framework/Versions/A/Libraries/libpq.5.6.dylib
   (compatibility version 5.0.0, current version 5.6.0)

That seems all well and good until my app's model library tries to link
against this framework. Then ld complains:

File not found:
@rpath/PostgreSQL.framework/Versions/A/Libraries/libpq.5.6.dylib for
architecture x86_64

The documentation for ld(1) makes it clear that it will search for the
re-exported library in order to link against it, but I'm not sure why
it's failing to find it. Adding "-F." to OTHER_LDFLAGS doesn't help. I'm
concerned that ld is just snarfing the "@rpath/PostgreSQL.framework…"
string, concatenating it with the working directory, and failing to find
a file on disk.

Does anyone have any tips on getting this working?

Thanks,
--Kyle Sluder

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Linking against a re-exported library
      • From: Michael Babin <email@hidden>
    • Re: Linking against a re-exported library
      • From: Scott Ribe <email@hidden>
    • Re: Linking against a re-exported library
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: Quick way to move method defs around?
  • Next by Date: Re: Linking against a re-exported library
  • Previous by thread: Re: Xcode 5.02/crashes
  • Next by thread: Re: Linking against a re-exported library
  • Index(es):
    • Date
    • Thread