0

Context

I'm developing an app in Qt with Qt Creator in OS X. Right now my file organization is a mess (every file is the same folder) so I've decided to move to another project structure that also allows me to also run unit tests.

What have I tried

Following this blog entry I tried to create the same project (just for testing purposes).

Problem

Everything compiles but when executing it gives an error Library not loaded. I thought that maybe I was doing something wrong so I cloned the example repo and try it again with a working example. But it gives me the same error:

dyld: Library not loaded: libmyapp.1.dylib
  Referenced from: /Users/(my build folder)/app/app
  Reason: image not found

The example is supposed to be right. The only changed I made is to remove the test subdir as I haven't installed yet UnitTest++ so my .pro file is like this:

TEMPLATE = subdirs
CONFIG+=ordered
SUBDIRS = \
    src \
    app

app.depends = src

OTHER_FILES += \
    defaults.pri

Am I doing something wrong? Is there any step that I forgot?

Edit 1:

Creating manually a Frameworks folder and adding the libmyapp.1.dylib inside the bundle makes the app work. But I think this step should be done automatically

Edit 2:

I've tried to run macdeployqt as suggested. It seems that the app is trying to get the library from the system path instead of the provided:

macdeployqt app.app
ERROR: no file at "/usr/lib/libmyapp.1.dylib"
Alberto S.
  • 7,409
  • 6
  • 27
  • 46
  • Do you understand what is required for a OSX/iOS binary to load a `.dylib`? I am no expert with Qt, but there is a .app bundler tool, which might do all the bundling (and `dylib`-setup) for you. Not sure tho. – trojanfoe Sep 02 '15 at 12:01
  • @trojanfoe the tool you are thinking of, for qt, is `macdeployqt` – Thalia Sep 03 '15 at 15:58

2 Answers2

0

I have done the following to get the correct dependencies on a lib in the executable...
This code in the application pro file sets dependencies and also places the files directly into the Contents/Framework folder inside bundle (I chose to make the executable do all the work)

# to get the dependencies
INCLUDEPATH += ../libmyapp
macx {
    LIBS += ../libmyapp/libmyapp.1.dylib
    PRE_TARGETDEPS += ../libmyapp/libmyapp.1.dylib
    MY.path = Contents/Frameworks
    MY.files = ../libmyapp/libmyapp.1.dylib
    QMAKE_BUNDLE_DATA += MY
} 

Alternatively you can make your lib become a framework .. 2 options in this post: How to create a Bundle Library (mh_bundle) with qmake on Mac OS X?

Would be good to read on the process of deploying an app on OS X... The tool trojanfoe was thinking of, for deploying qt apps, is called macdeployqt

Thalia
  • 13,637
  • 22
  • 96
  • 190
  • Still the same issue :( – Alberto S. Sep 03 '15 at 17:22
  • Check out similar questions: http://stackoverflow.com/q/17703510/1217150 You have to run the install_name_tool on dependencies too. Steps are also explained really well in the link I posted about deploying an app in OS X - they mention how to deploy Qt framework libs, but same process applies to external libs – Thalia Sep 03 '15 at 17:52
0

Working with bundles of C++ programs with dependencies on Mac OS X can be a real pain. A workaround until you actually need to ship your app as a bundle is tell Qt not to create a bundle at all. Add the following to your app.pro file:

CONFIG -= app_bundle

Then you may add the dylib to the output directory yourself and it should hopefully work fine.

Another option is to set/add the environment variable LD_LIBRARY_PATH in the Run settings for your project in Qt Creator to point to the path where your compiled dylib is located.

I'm not sure that the above works, but those are my best guesses from earlier experience with similar issues. Also, make sure you are using the newest versions of Qt and Qt Creator.

dragly
  • 1,445
  • 11
  • 14