Igor
Igor

Reputation: 6255

Failing to properly copy the library to Application Bundle

ALL,

I am working with the Xcode. My project contains one executable binary and couple dylibs with the inter-dependencies

In my Xcode project I successfully created an script phase to copy dylib files (all of them) inside the Application Bundle. However when I try to run the application from the Terminal - it fails.

The error I am gettting is as follows:

Dyld Error Message:
  Library not loaded: /usr/local/lib/liblibpropertypages.dylib
  Referenced from: /Users/igorkorot/dbhandler/dbhandler/Build/Products/Debug/dbhandler.app/Contents/Frameworks/liblibdbwindow.dylib
  Reason: image not found

But in the script I have the following code:

cp -f ~/dbhandler/dbhandler/Build/Products/Debug/liblibpropertypages.dylib "$TARGET_BUILD_DIR/$TARGET_NAME.app/Contents/Frameworks/liblibpropertypages.dylib"
install_name_tool -change /usr/local/lib/liblibpropertypages.dylib @executable_path/../Frameworks/liblibpropertypages.dylib "$TARGET_BUILD_DIR/$TARGET_NAME.app/Contents/MacOS/$PRODUCT_NAME"

cp -f ~/dbhandler/dbhandler/Build/Products/Debug/liblibdbwindow.dylib "$TARGET_BUILD_DIR/$TARGET_NAME.app/Contents/Frameworks/liblibdbwindow.dylib"
install_name_tool -change /usr/local/lib/liblibdbwindow.dylib @executable_path/../Frameworks/liblibdbwindow.dylib "$TARGET_BUILD_DIR/$TARGET_NAME.app/Contents/MacOS/$PRODUCT_NAME"

So the place to load the liblibdbwindow.dylib is changed, but the place to load liblibpropertypages.dylib is not. The code is exactly the same.

What am I missing?

TIA!

Upvotes: 0

Views: 341

Answers (1)

Siguza
Siguza

Reputation: 23840

One of your libraries depends on the other one, so you need to change the reference there too.

install_name_tool -change /usr/local/lib/liblibpropertypages.dylib @executable_path/../Frameworks/liblibpropertypages.dylib "$TARGET_BUILD_DIR/$TARGET_NAME.app/Contents/Frameworks/liblibdbwindow.dylib"

And you'll probably want to change the IDs of those libraries as well:

install_name_tool -id @executable_path/../Frameworks/liblibpropertypages.dylib "$TARGET_BUILD_DIR/$TARGET_NAME.app/Contents/Frameworks/liblibpropertypages.dylib"
install_name_tool -id @executable_path/../Frameworks/liblibdbwindow.dylib "$TARGET_BUILD_DIR/$TARGET_NAME.app/Contents/Frameworks/liblibdbwindow.dylib"

Upvotes: 1

Related Questions