深度Linux系统上编译Albert使用
Mac上有Alfred这样的辅助软件,非常好用,Linux下也有不少,比如Albert/Mutate,这两个都是Qt开发的,还有一些是Electron开发的,虽然看起来不错,但是我本身不太喜欢用Electron的软件,体积大运行效率低,所以就不考虑了,Mutate很久没人维护了,所以我一直用Albert,下载了二进制的deb包发现安装报错,缺少很多个库,我也不想添加源来安装,Linux系统一个很大的问题就是你添加各种源,然后安装各种lib,突然有一天就报错了,各种程序无法运行,甚至系统都无法升级,虽然这些问题都能解决,但是要浪费不少时间,现在用了深度系统之后,GUI软件基本上只用系统自带商店下的,所以干脆就自己checkout源码下来编译最新的版本了,这样既可以用最新的功能或者修复最新的bug,还可以自己完全掌控。
于是开始动手,根据官方文档,先创建albert-build
目录进行编译, 直接报错如下
➜ albert-build git:(dev) ✗ cmake ../../albert -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
CMake Error at lib/globalshortcut/CMakeLists.txt:5 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" (requested
version 5.5.0) with any of the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
提示没有配置Qt编译环境,这个只需要cmake添加参数CMAKE_PREFIX_PATH指向QtSDK就行了,比如我装的Qt5.14.2,添加如下
cmake ../../albert -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/cmake/Qt5
继续编译,再次报错
Scanning dependencies of target calculator
[ 44%] Building CXX object plugins/calculator/CMakeFiles/calculator.dir/src/configwidget.cpp.o
[ 44%] Building CXX object plugins/calculator/CMakeFiles/calculator.dir/src/extension.cpp.o
/home/user/Workspace/QtPrj/albert/plugins/calculator/src/extension.cpp:11:22: fatal error: muParser.h: 没有那个文件或目录
#include "muParser.h"
^
compilation terminated.
提示缺少一个头文件,直接运行sudo apt install libmuparser-dev
安装好libmuparser继续编译,编译完成后使用sudo make install
安装,然后直接运行albert,还是报错,如下
albert: error while loading shared libraries: libQt5Charts.so.5: cannot open shared object file: No such file or directory
用ldd直接查看albert缺少哪些库ldd /usr/bin/albert
➜ ldd /usr/bin/albert
/usr/bin/albert: /lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.14' not found (required by /usr/bin/albert)
/usr/bin/albert: /lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.14' not found (required by /usr/bin/../lib/x86_64-linux-gnu/albert/libalbert.so)
/usr/bin/albert: /lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.14' not found (required by /usr/bin/../lib/x86_64-linux-gnu/albert/libxdg.so)
只是报缺少libQt5Core.so.5,直接去/etc/ld.so.conf.d
下创建一个qt5.conf
的文件,里面写入QtSDK里面的运行库路径,比如/home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib
,然后运行sudo ldconfig -v|grep qt5
查看,配置正确后运行albert就能跑起来了,但是这样只能在本机上面跑,这时候再ldd /usr/bin/albert
就能看到albert所需要的库文件,以此类推对其他的so也检查一下。
➜ ldd /usr/bin/albert|grep Qt
libQt5Concurrent.so.5 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libQt5Concurrent.so.5 (0x00007ff0add90000)
libQt5Network.so.5 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libQt5Network.so.5 (0x00007ff0ad9e0000)
libQt5Sql.so.5 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libQt5Sql.so.5 (0x00007ff0ad790000)
libQt5Charts.so.5 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libQt5Charts.so.5 (0x00007ff0acf48000)
libQt5X11Extras.so.5 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libQt5X11Extras.so.5 (0x00007ff0acd40000)
libQt5Widgets.so.5 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libQt5Widgets.so.5 (0x00007ff0ac1a0000)
libQt5Gui.so.5 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libQt5Gui.so.5 (0x00007ff0ab880000)
libQt5Core.so.5 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libQt5Core.so.5 (0x00007ff0ab0a0000)
libicui18n.so.56 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libicui18n.so.56 (0x00007ff0a9260000)
libicuuc.so.56 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libicuuc.so.56 (0x00007ff0a8ea8000)
libicudata.so.56 => /home/user/DevTools/Qt5.14.2/5.14.2/gcc_64/lib/libicudata.so.56 (0x00007ff0a74c0000)
把找出来的so库复制到albert的插件统计目录下,然后在写一个启动的脚本文件就可以了,大致如下,qtplugins用户放置用的插件
#!/bin/sh
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/albert:$LD_LIBRARY_PATH
export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/albert/qtplugins
albert