一直依赖 QT-based App 下 Fcitx 无法输入中文的问题都让我很恼火,用的比较多的 RStudio 先后两次去 Support 发帖无果,Mendeley 也去发帖过一次,官方回复“知道了,但是目前这个问题优先级很低”…
网上看到过几次有人说自己编译 QT
和 fcitx-qt
得到 libfcitxplatforminputcontextplugin.so
放到指定位置就可以。我试过下载别人编译好的试过都没成功,自己不是很会编译啥的怕把系统组件搞乱又懒得编译…直到前天又看到 Mendeley Fcitx Problem 这个帖子,在下面留言,po 主表示多几个 QT 也不会搞坏系统我才决定尝试下。
好的,废话少说,开始。
QT
下载 qt-everywhere-opensource-src-5.5.1.tar.xz
并解压,进入目录。
# 准备安装 QT 的目录
sudo mkdir /opt/qt.5..5.1
./configure --prefix=/opt/qt5.5.1 -no-openssl
碰到一大堆报错 XCB
啥的,查了下直接加 -qt-xcb
就行了,我也不知道 XCB
干嘛的,这不是重点。
./configure --prefix=/opt/qt5.5.1 -no-openssl -qt-xcb
顺利同过。然后三部曲后两步:
make -j4
# 燃烧吧 CPU。
# 我的 Intel Core i5-6300HQ @ 4x 3.2GHz 大概编了 20~30min。
sudo make install
fictx-qt
接下来是 fcitx-qt
。在编译它之前要让刚刚编译好的 QT 发挥作用,所以要改路径,我的做法也是临时export
一下,只要这个终端不关都能起作用,但是要记得后面的过程都在这个终端完成。
export PATH="/opt/qt5.5.1/bin/:$PATH"
git clone https://github.com/fcitx/fcitx-qt5.git
cd fcitx-qt5
cmake .
是的,又有问题了。
CMake Error at CMakeLists.txt:8 (find_package):
Could not find a package configuration file provided by "ECM" (requested
version 1.4.0) with any of the following names:
ECMConfig.cmake
ecm-config.cmake
Add the installation prefix of "ECM" to CMAKE_PREFIX_PATH or set "ECM_DIR"
to a directory containing one of the above files. If "ECM" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/path/to/fcitx-qt5/CMakeFiles/CMakeOutput.log".
Google 一下,哦,sudo apt install extra-cmake-modules
就行了。继续:
cmake .
# 错误又来了
-- Could NOT find XKBCommon_XKBCommon (missing: XKBCommon_XKBCommon_LIBRARY XKBCommon_XKBCommon_INCLUDE_DIR)
CMake Error at /usr/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find XKBCommon (missing: XKBCommon_LIBRARIES XKBCommon) (Required
is at least version "0.5.0")
Call Stack (most recent call first):
/usr/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
cmake/FindXKBCommon.cmake:30 (find_package_handle_standard_args)
CMakeLists.txt:33 (find_package)
-- Configuring incomplete, errors occurred!
See also "/path/to/fcitx-qt5/CMakeFiles/CMakeOutput.log".
WTF???..不要急不要急,Google 一下,哦,sudo apt install libxkbcommon-dev
。继续:
cmake .
# 呵呵
-- Found XKBCommon_XKBCommon: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (found version "0.7.1")
-- Found XKBCommon: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (found suitable version "0.7.1", minimum required is "0.5.0") found components: XKBCommon
CMake Error at CMakeLists.txt:36 (find_package):
By not providing "FindFcitx.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Fcitx", but
CMake did not find one.
Could not find a package configuration file provided by "Fcitx" (requested
version 4.2.8) with any of the following names:
FcitxConfig.cmake
fcitx-config.cmake
Add the installation prefix of "Fcitx" to CMAKE_PREFIX_PATH or set
"Fcitx_DIR" to a directory containing one of the above files. If "Fcitx"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/path/to/fcitx-qt5/CMakeFiles/CMakeOutput.log".
哦,知道了,Google。哦,sudo apt install fcitx-libs-dev
。好,继续:
cmake .
# 过了..............
make -j4
手别抖不要惯性 sudo make install,不需要。
现在platforminputcontext
目录下应该已经有了新鲜出炉的libfcitxplatforminputcontextplugin.so
了,然后就好了:
sudo cp platforminputcontext/libfcitxplatforminputcontextplugin.so /opt/mendeleydesktop/plugins/qt/plugins/platforminputcontexts
再终端打开 Mendeley 试试 Fcitx 已经可以用了。不保险,直接鼠标点点点菜单找到 Mendeley 打开输入法还没挂,OK。
RStudio
接下来一样,在 RStudio 菜单的关于里看了下,基于 QT-5.4.0,那就下载qt-everywhere-opensource-src-5.4.0.tar.xz
好了。
你以为帖子完了,怎么可能,Naive。
./configure --prefix=/opt/qt.5.4.0 -no-openssl -qt-xcb
直接报错:
ln -s libQt5Widgets.so.5.4.0 libQt5Widgets.so
ln -s libQt5Widgets.so.5.4.0 libQt5Widgets.so.5
ln -s libQt5Widgets.so.5.4.0 libQt5Widgets.so.5.4
rm -f ../../lib/libQt5Widgets.so.5.4.0
mv -f libQt5Widgets.so.5.4.0 ../../lib/
rm -f ../../lib/libQt5Widgets.so
rm -f ../../lib/libQt5Widgets.so.5
rm -f ../../lib/libQt5Widgets.so.5.4
mv -f libQt5Widgets.so ../../lib/
mv -f libQt5Widgets.so.5 ../../lib/
mv -f libQt5Widgets.so.5.4 ../../lib/
make[3]: Leaving directory '/home/adam/Downloads/Persepolis/qt-everywhere-opensource-src-5.4.0/qtbase/src/widgets'
make[2]: Leaving directory '/home/adam/Downloads/Persepolis/qt-everywhere-opensource-src-5.4.0/qtbase/src'
Makefile:45: recipe for target 'sub-src-make_first' failed
make[1]: *** [sub-src-make_first] Error 2
make[1]: Leaving directory '/home/adam/Downloads/Persepolis/qt-everywhere-opensource-src-5.4.0/qtbase'
Makefile:70: recipe for target 'module-qtbase-make_first' failed
make: *** [module-qtbase-make_first] Error 2
一头雾水,连报错信息都基本没有。二话不说,Google,靠谱的办法试试看,比如这个帖子:Build Qt Static Make Error - [SOLVED], 官方论坛官方回答,看着靠谱。哦:
./configure --prefix=/opt/qt.5.4.0 -release -opensource -confirm-license -static -qt-xcb -no-openssl -no-glib -no-pulseaudio -no-alsa -opengl desktop -nomake examples -nomake tests
#然后真的过了
make -j4
# 燃烧吧 CPU。Winter is Coming!!!!!!
rm -f ../../lib/libQt5Widgets.a
mv -f libQt5Widgets.a ../../lib/
make[3]: Leaving directory '/home/adam/Downloads/Persepolis/qt-everywhere-opensource-src-5.4.0/qtbase/src/widgets'
make[2]: Leaving directory '/home/adam/Downloads/Persepolis/qt-everywhere-opensource-src-5.4.0/qtbase/src'
Makefile:45: recipe for target 'sub-src-make_first' failed
make[1]: *** [sub-src-make_first] Error 2
make[1]: Leaving directory '/home/adam/Downloads/Persepolis/qt-everywhere-opensource-src-5.4.0/qtbase'
Makefile:70: recipe for target 'module-qtbase-make_first' failed
make: *** [module-qtbase-make_first] Error 2
还是上面那个报错…我也不知道为啥了,好吧老实点先把不知道的从命令拿掉,重新./configure --prefix=/opt/qt.5.4.0 -release -opensource -confirm-license -no-openssl -qt-xcb -nomake examples -nomake tests
。
报错依然,上网一顿查,Google 看了 N 多都是交叉编译的问题,而且错误和我不完全一样。百度,各种论坛都是提问题的没有回答的。
N 久无果,中间 2~3个小时过去了。
我开始思索是不是我哪里做法有问题。
这时我突然记起来之前尝试编译 RStudio 的时候,从 GitHub 上安装依赖的脚本里看到编译 RStudio 的时候会依照里面的设置从他们自己的 AWS 服务器上下载他们精(魔)简(改)的 QT binary 的。这洋一想我直接去用他们的 QT 编译岂不是更好。二话不说去 GitHub 看他们的 QT 放在哪儿。你看他们的 rstudio/dependencies/linux/install-qt-sdk
里写的:
# presume 5.4.0
QT_VERSION=5.4.0
# test for libgstreamer
which apt-cache > /dev/null
if [ $? == 0 ]; then
# debian (currently no test for CentOS based systems)
apt-cache show libgstreamer1.0 > /dev/null
if [ $? == 0 ]; then
QT_VERSION=5.4.2
fi
fi
QT_SDK_BINARY=QtSDK-${QT_VERSION}-${QT_ARCH}.tar.gz
QT_SDK_URL=https://s3.amazonaws.com/rstudio-buildtools/$QT_SDK_BINARY
# set Qt SDK dir if not already defined
if [ -z "$QT_SDK_DIR" ]; then
QT_SDK_DIR=~/Qt${QT_VERSION}
fi
if ! test -e $QT_SDK_DIR
then
# download and install
wget $QT_SDK_URL -O /tmp/$QT_SDK_BINARY
cd `dirname $QT_SDK_DIR`
tar xzf /tmp/$QT_SDK_BINARY
rm /tmp/$QT_SDK_BINARY
else
echo "Qt $QT_VERSION SDK already installed"
fi
暴力暴力,够社会。
直接自己拼接出 QtSDK-5.4.0 的地址下下来了。由于这个已经是 binary 了就不需要我再编译了,直接用就行。
然后就是跟前面差不多了。解压他们的 QT 放到 /opt/qt.5.4.0
,然后重新编译 fictx-qt5
,得到libfcitxplatforminputcontextplugin.so
。
注意,刚刚是 Mendeley 所以最后libfcitxplatforminputcontextplugin.so
就拷贝到/opt/mendeleydesktop/plugins/qt/plugins/platforminputcontexts/
,即谁要给谁。同理,RStudio 就应该拷贝到/usr/lib/rstudio/bin/plugins/platforminputcontexts/
了。
然后试了下 RStudio 终于,Fcitx 起来了。
总结
看起来我这个基本上一个小时能解决,事实上我从昨晚到现在,用的总时间起码昨晚 3+ 小时,今天早上到现在下午起码 4+ 小时。中间我为了记录过程开了一个记事本现在 600+ 行了…庭有枇杷树,吾妻死之年手植也,今已亭亭如盖矣。
但是我仍然很开心,我觉得我知道了一些新东西,踩了一些新的坑,问题最后也解决了(大概下次谁更新了可能会再来一次,但下次应该就轻车熟路了)。
写出来无非想让后来人可以借鉴,并且希望和我一样很多东西不懂的人可以看到解决问题的过程和思路,让论坛新人可以参考。
说了这么多,总结:
- Google;
- 耐心;
- 尝试。