Qt Creator cannot find libraries installed by Homebrew via pkg-config
-
Hi,
I have installed the latest Qt 5.5.1 (released 2015-10-13) from the official installer on my Mac (10.11.2) and I want to use external libraries in my project, for instance libsndfile, which I have installed via Homebrew.
When running
pkg-config --libs sndfile
manually from the Terminal, it returns-L/usr/local/Cellar/libsndfile/1.0.26/lib -lsndfile
, so everything seems to be in the right place.I then tried to add libsndfile to my qmake project file, as specified in the docs, choosing the “System package” option, and entering
sndfile
in the prompt on the following page in the wizard, resulting in the following two lines being added to my project file:unix: CONFIG += link_pkgconfig unix: PKGCONFIG += sndfile
But now, Qt Creator complains:
Project ERROR: sndfile development package not found
and i cannot compile my project any more.
As a sidenote, the same project file compiles fine on an Arch Linux machine with libsndfile installed as a normal system library from their official repository.
I found that there was a bug with Qt Creator and pkg-config libraries on Mac OSX. But a fix for this seems to be merged with the 5.5 line since 2015-09-28. So it should be part of my version (see above?), right?
I've also tried the solutions suggested in a stack overflow question without success. I can hit the green compile buttons again in Qt Creator after adding
QT_CONFIG -= no-pkg-config
to my project file, but I still get asndfile development package not found
error, even after tinkering with /etc/launchd.conf or /etc/paths.d/local to add /usr/local/bin to my PATH (and re-launching Qt Creator afterwards).What am I doing wrong? Is it somehow possible to use libraries installed via Homebrew on a Mac?
-
Hi,
Where are the pkg-config files from Homebrew located ?
-
The actual files reside in
/usr/local/Cellar/<package_name>/<package_version>/lib/pkgconfig/<package name>.pc
and those files get symlinked to/usr/local/lib/pkgconfig/<package_name>.pc
. So, in case of libsndfile, it's:/usr/local/lib/pkgconfig/sndfile.pc -> /usr/local/Cellar/libsndfile/1.0.26/lib/pkgconfig/sndfile.pc
. -
You may need to set the PKG_CONFIG_PATH environment variable in your build environment for pkg-config to search there and find your brew installed libraries.
-
Hmm, adding /usr/local/lib/pkgconfig as PKG_CONFIG_PATH to the Build Environment for my project did not help. But adding /usr/local/bin to the PATH of my build environment seems to do the trick. I saw that it was missing from there, so I gave it a try.
I am not sure where to go from here. Is there a portable way to alter the build environment from the project file? I tried something like
mac: PATH += /usr/local/bin
but that did not work. So do changes like this always have to be altered manually in the Project Settings in Qt Creator?Perhaps using Homebrew for installing external libraries on OSX is not the best solution with Qt Creator?
-
Do you mean that pkg-config wasn't found when running Qt Creator ?
If so, then the usual trick to modify PATH in your .profile or .bash_rc will make it work from the command line but not for the application you start from e.g. Spotlight or by clicking on them. IIRC you can add a path to
/etc/paths.d/mypath
to make it system wide -
Can you please share the solution? I am facing the exact same problem, but with gstreamer-1.0, as I posted here: https://forum.qt.io/topic/112301/gstreamer-1-0-not-found-on-mac
Thanks!