0

In deploying my OSX application, the .app file was having trouble finding the custom dylib that I coded. Here's the strange thing about that, though:

  • It worked in Qt Creator just fine.
  • If I went to command line, cd'd into the directory where my executable app (LibraryTester) and dylib file were located, and did ./LibraryTester, it worked just fine.
  • If I doubleclicked the executable or the .app file icon, the program would crash because it couldn't find the custom dylib that I created.

Now, I can fix this easily by using install_name_tool like so:

install_name_tool LibraryTester -change mycustom.1.dylib @loader_path/mycustom.1.dylib

(the key thing being the @loader_path variable)

...however, is there a setting in the .pro file of my Qt 5.5 project so that I don't have to keep doing that all the time on deployment?

Volomike
  • 23,743
  • 21
  • 113
  • 209

2 Answers2

0

The fix is to use install_name_tool on the library itself before it is added to the main application project. See, where I went wrong was trying to do this on the application (LibraryTester) instead of the dylib.

For the fix, I ran:

install_name_tool -id @loader_path/mycustom.1.dylib mycustom.1.dylib

on the custom dylib file. The @loader_path translates to "the same directory of the main application". So, in your .app folder, that would be Contents/MacOS.

If you want, you can switch this with @rpath and that would translate to Contents/Frameworks.

This lets you test on the fly with each compile of your main application. See, some things don't present themselves until you doubleclick the .app folder to launch your application. Sure, you might be able to run your app and its related dylib from command line just fine, and you might able to run it from inside Qt Creator, but there are rare instances where some things might not be presented as a problem until you doubleclick the .app folder.

Now, that gives you an interim solution such that you don't need to keep doing command line stuff to make your dylib work with your executable when doubleclicking the .app file. However, when you are ready to take this project into production, you should use the command macdeployqt.

Now, here's another trick you might not know for Qt/C++ on MacOS. You can add the following to your .pro file and it will automatically copy out your dylib file into the same directory as your executable file (LibraryTester, in my example):

mac {
  Resources.files += mycustom.1.dylib
# you can put more of these as you need, and it can even copy folders
# Resources.files += blah blah
  Resources.path = Contents/MacOS
  QMAKE_BUNDLE_DATA += Resources
}
Volomike
  • 23,743
  • 21
  • 113
  • 209
0

add QMAKE_LFLAGS_SONAME to your custom dylib's .pro file

example:

QMAKE_LFLAGS_SONAME = -Wl,-install_name,@executable_path/../Frameworks/

C.XL
  • 1
  • 4