在Mac OSX上将pkg-config与Qt Creator/qmake一起使用 [英] Using pkg-config with Qt Creator/qmake on Mac OSX

查看:146
本文介绍了在Mac OSX上将pkg-config与Qt Creator/qmake一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pkg-config在Mac OSX(10.8.4)中并没有成为标准.对于我的Qt项目,我想使用pkg-config链接到协议缓冲区,以便可移植.选择Qt的关键是首先要有一个便携式应用.

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.

但是,qmake不允许我使用pkg-config. 使用pkg-config输出将库链接到QT项目给出了一个应该起作用的简单方法.但这不是

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

CONFIG += link_pkgconfig PKGCONFIG += protobuf 一起出现错误Project ERROR: Package protobuf not found

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

Eventhough pkg-config和protobuf是使用自制程序并在路径中安装的.而且问题出在所有pkg-config软件包上.

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.

推荐答案

解决方案

QT_CONFIG -= no-pkg-config行添加到项目文件中.

Solution

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

在Mac的Qt程序包中,默认情况下禁用了对pkg-config的支持.

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

因此,将qmake配置为假定系统上没有pkg-config.

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

他们通过宏变量QT_CONFIG

qmaketest $ grep QT_CONFIG/Applications/Other/Qt5.0.2/5.0.2/clang_64/mkspecs/qconfig.pri QT_CONFIG + =最小配置小配置中配置大配置全配置build_all debug_and_release no-pkg-config rpath corewlan并发音频后端v8 v8snapshot调试版本qt_framework

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

因此在项目文件中添加行QT_CONFIG -= no-pkg-config即可解决该问题.

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

另一个问题是Finder启动的Qt Creator路径中没有/usr/local/bin. 如 https://serverfault.com/questions/16355/how中所述-to-set-global-path-on-os-x

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).

在编辑了@vmarquet指出的launchd.conf文件之后,还重新启动了Qt Creator

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

这篇关于在Mac OSX上将pkg-config与Qt Creator/qmake一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆