Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using pkg-config with Qt Creator/qmake on Mac OSX

pkg-config doesn't come stantdard with Mac OSX (10.8.4). For my Qt project I wanted to use pkg-config to link in protocol-buffer, so that it would be portable. The very point of choosing Qt was to have a portable app in the first place.

However, qmake would not let me use pkg-config. Linking libraries to a QT project using pkg-config output gives a simple recipe that should work. But it doesn't

with CONFIG += link_pkgconfig PKGCONFIG += protobuf I'm getting the error Project ERROR: Package protobuf not found

Eventhough pkg-config and protobuf are installed using homebrew and in path. And the problem is with all pkg-config packages.

qmaketest$which pkg-config
/usr/local/bin//pkg-config
qmaketest$pkg-config --cflags --libs libssl
-lssl -lcrypto -lz 
qmaketest$cat project.proj 
QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = project
TEMPLATE = app


SOURCES += 

HEADERS  += 

FORMS    += 

OTHER_FILES += 

CONFIG += link_pkgconfig
PKGCONFIG += libssl

qmaketest$/Applications/Other/Qt5.0.2/5.0.2/clang_64/bin/qmake project.proj 
Project ERROR: Package libssl not found

When I dug deeper I found a solution.

like image 695
Spundun Avatar asked Jun 06 '13 20:06

Spundun


1 Answers

Solution

Add the line QT_CONFIG -= no-pkg-config to the project file.

Explanation

Support for pkg-config is disabled by default in the Qt package for mac.

So the qmake is configured to assume that there is no pkg-config on the system.

They do that through macro variable QT_CONFIG

qmaketest$grep QT_CONFIG /Applications/Other/Qt5.0.2/5.0.2/clang_64/mkspecs/qconfig.pri QT_CONFIG += minimal-config small-config medium-config large-config full-config build_all debug_and_release no-pkg-config coreservices accessibility opengl shared qpa reduce_exports getaddrinfo ipv6ifname getifaddrs png freetype system-zlib nis cups iconv openssl rpath corewlan concurrent audio-backend v8 v8snapshot debug release qt_framework

So adding a line QT_CONFIG -= no-pkg-config to the project file fixed it.

For Qt Creator

One more problem is that Qt Creator launched by Finder won't have /usr/local/bin in the path. As described in https://serverfault.com/questions/16355/how-to-set-global-path-on-os-x , PATH is getting set somewhere other than launchd.conf and I don't know where and http://overwatering.org/blog/2012/08/setting-path-osx-mountain-lion/ you need to add export PATH=/usr/local/bin:$PATH to /etc/launchd.conf (create the file if it doesn't exist).

Also relaunch Qt Creator after editing the launchd.conf file as pointed out by @vmarquet

like image 76
Spundun Avatar answered Nov 23 '22 15:11

Spundun