Mac下用brew配置QT开发环境
用brew
的好处是稍微省心一些,不用折腾更新什么的,万一要重装什么的也可以brew bundle dump
然后在新机器上brew bundle
一把了事。
brew
安装QT开发环境也确实简单,两条命令而已:
brew install qt brew install qt-creator
brew安装的时候已经安装好了`Xcode Command Line Tools`等,必要的话把它更新一下(App Store会自动提醒)。网上有些教程说安装QT之前要安装`Xcode`完整版,这个我已经没有条件试验了,但我印象中是先`brew install qt`然后才安装的`Xcode`。
# 配置
上面两条命令之间是没有关联的,后装的qt-creator
不会自动检测到前面的qt
(qt
这个包是QT开发工具链),所以需要配置。
首先brew info qt
一下,可以看到:
╰─ brew info qt qt: stable 5.10.0 (bottled), HEAD [keg-only] Cross-platform application and UI framework https://www.qt.io/ /usr/local/Cellar/qt/5.10.0 (9,351 files, 290MB) Poured from bottle on 2017-12-30 at 20:16:37 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/qt.rb ==> Dependencies Build: pkg-config ✘ Optional: mysql ✘, postgresql ✘ ==> Requirements Build: xcode ✔ Required: macOS >= 10.8 ✔ ==> Options --with-docs Build documentation --with-examples Build examples --with-mysql Build with mysql support --with-postgresql Build with postgresql support --HEAD Install HEAD version ==> Caveats We agreed to the Qt opensource license for you. If this is unacceptable you should uninstall. This formula is keg-only, which means it was not symlinked into /usr/local, because Qt 5 has CMake issues when linked. If you need to have this software first in your PATH run: echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.zshrc For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/qt/lib CPPFLAGS: -I/usr/local/opt/qt/include
显然,为了不跟系统过多耦合导致问题,qt
包根本没把自己注册到系统里,也就是装完qt
也不能直接在命令行qmake
,而是需要/usr/local/opt/qt/bin/qmake
。知道了qmake
工具链的路径,就可以开始配置:
- 这时候应该已经好了,去新建项目测试一下吧。首先看项目是不是可以正常编译运行,然后测试能不能单步调试。