Perusal, Synthesis, Bliss

October 29, 2013: compilation of KSokoban for Qt4

Qt 4

KSokoban is a game I played several years ago (to the best of my memory, 2002 or 2003, and then again a bit in 2005 or 2006). The original project page is available here. It has not been updated since 1999.
It was available in KDE3, but not in KDE4. Someone has ported the project to KDE4 (here), i.e. in fact Qt 4. The sourceforge page is here. I followed the instructions of compilation available at the first address:
$ mkdir build
$ cd build
$ cmake ..
$ make
It worked perfectly on my work computer, using Linux Kubuntu 13.04 distribution. But it does not work on my home machine, which however uses the same distribution. I obtain an error when calling cmake:
$ cmake ..
[...]
-- Performing Test __KDE_HAVE_GCC_VISIBILITY
-- Performing Test __KDE_HAVE_GCC_VISIBILITY - Success
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
QT_QT_INCLUDE_DIR
   used as include directory in directory /usr/local/src/INSTALLED/ksokoban/build/CMakeFiles/CMakeTmp
CMake Error: Internal CMake error, TryCompile configure of cmake failed
CMake Error at /usr/share/kde4/apps/cmake/modules/FindKDE4Internal.cmake:1297 (message):
  Qt compiled without support for -fvisibility=hidden.  This will break
  plugins and linking of some applications.  Please fix your Qt installation
  (try passing --reduce-exports to configure).
Call Stack (most recent call first):
  /usr/share/cmake-2.8/Modules/FindKDE4.cmake:95 (find_package)
  CMakeLists.txt:3 (find_package)
Opening the cmake generated file CMakeCache.txt, we read in particular:
[...]
QT_INCLUDE_DIR:PATH=/usr/include/qt5
[...]
QT_QT_INCLUDE_DIR:PATH=QT_QT_INCLUDE_DIR-NOTFOUND
[...]
So we may be tempted to change manually the second line:
QT_QT_INCLUDE_DIR:PATH=/usr/include/qt5
When we do that, we obtain another error:
$ cmake ..
-- Found Qt-Version 5.0.1 (using /usr/bin/qmake)
Change Dir: /usr/local/src/INSTALLED/ksokoban/build/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make "cmTryCompileExec3266706522/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec3266706522.dir/build.make CMakeFiles/cmTryCompileExec3266706522.dir/build
make[1]: Entering directory ‘/usr/local/src/INSTALLED/ksokoban/build/CMakeFiles/CMakeTmp’
/usr/bin/cmake -E cmake_progress_report /usr/local/src/INSTALLED/ksokoban/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec3266706522.dir/check_qt_visibility.cpp.o
/usr/local/bin/c++ -Wnon-virtual-dtor -Wno-long-long -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-check-new -fno-common -Woverloaded-virtual -fno-threadsafe-statics -fvisibility=hidden -I/usr/include/qt5/QtXml -I/usr/include/qt5/QtTest -I/usr/include/qt5/QtSql -I/usr/include/qt5/QtOpenGL -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtDBus -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I/usr/include/qt5 -I/usr/local/src/INSTALLED/ksokoban/build/CMakeFiles/CMakeTmp/QT_MKSPECS_DIR-NOTFOUND/default -o CMakeFiles/cmTryCompileExec3266706522.dir/check_qt_visibility.cpp.o -c /usr/local/src/INSTALLED/ksokoban/build/CMakeTmp/check_qt_visibility.cpp
In file included from /usr/include/qt5/QtCore/QtGlobal:1:0,
from /usr/local/src/INSTALLED/ksokoban/build/CMakeTmp/check_qt_visibility.cpp:1:
/usr/include/qt5/QtCore/qglobal.h:1079:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC or -fPIE."
make[1]: *** [CMakeFiles/cmTryCompileExec3266706522.dir/check_qt_visibility.cpp.o] Error 1
make[1]: Leaving directory ‘/usr/local/src/INSTALLED/ksokoban/build/CMakeFiles/CMakeTmp’
make: *** [cmTryCompileExec3266706522/fast] Error 2
So we are tempted to change the line of CMakeCache.txt:
CMAKE_CXX_FLAGS:STRING=
into
CMAKE_CXX_FLAGS:STRING=-fPIC
This time it works:
$ cmake ..
-- Found Qt-Version 5.0.1 (using /usr/bin/qmake)
-- Found KDE 4.10 include dir: /usr/include
-- Found KDE 4.10 library dir: /usr/lib
-- Found the KDE4 kconfig_compiler preprocessor: /usr/bin/kconfig_compiler
-- Found automoc4: /usr/bin/automoc4
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/INSTALLED/ksokoban/build
But the compilation fails:
$ make
Scanning dependencies of target ksokoban_automoc
Generating ModalLabel.moc
Generating PlayField.moc
Generating MainWindow.moc
[  0%] Built target ksokoban_automoc
Scanning dependencies of target ksokoban
[  5%] Building CXX object CMakeFiles/ksokoban.dir/ksokoban_automoc.o
[ 11%] Building CXX object CMakeFiles/ksokoban.dir/Bookmark.o
In file included from /usr/include/KDE/KApplication:1:0,
                 from /usr/local/src/INSTALLED/ksokoban/Bookmark.cpp:28:
/usr/include/KDE/../kapplication.h:45:30: fatal error: QtGui/QApplication: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/ksokoban.dir/Bookmark.o] Error 1
make[1]: *** [CMakeFiles/ksokoban.dir/all] Error 2
make: *** [all] Error 2
The problem is that there has been refactoring with a reduced kernel in Qt5, now we have QGuiApplication and QCoreApplication. QApplication is now in QGuiApplication (see here). So we have to force the compilation for Qt4, not Qt5. The other alternative is to change the code of KSokoban, but I have not the time for that. In the past, I was able to choose between Qt4 and Qt5 by using update-alternatives; however in Kubuntu 13.04, I obtain:
$ sudo update-alternatives --config qmake  
update-alternatives: error: no alternatives for qmake
More strangely, it seems that the qmake version seen in root is not the same as an ordinary user:
$ qmake --version
QMake version 2.01a
Using Qt version 4.8.4 in /usr/lib/x86_64-linux-gnu
$ which qmake
/usr/lib/x86_64-linux-gnu/qt4/bin/qmake
$ sudo su
$ qmake --version
QMake version 3.0
Using Qt version 5.0.1 in /usr/lib/x86_64-linux-gnu
$ which qmake
/usr/bin/qmake
Up to now, I made compilations as root: this explains my problems. It will be interesting to see if update-alternatives will be restored as before in the future. In the meantime, a temporary solution is to put for ROOT user a $PATH variable similar to as an ordinary user:
$ PATH=/usr/lib/x86_64-linux-gnu/qt4/bin:$PATH
$ echo $PATH
/usr/lib/x86_64-linux-gnu/qt4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ make --version
QMake version 2.01a
Using Qt version 4.8.4 in /usr/lib/x86_64-linux-gnu
Now it works like a charm:
$ cd build
$ cmake ..
$ make
$ ln -s ‘pwd‘/ksokoban /usr/local/bin/
$ ksokoban

Update in November 2020: Qt 5

I have downloaded the last version at here. Following the procedure indicated in the README file cmake returns an error:
$ cmake
[…]
CMake Error at CMakeLists.txt:11 (find_package):
  Could not find a package configuration file provided by "ECM" (requested
  version 1.7.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.
So I did
$ wajig install extra-cmake-modules
$ cmake
[…]
CMake Error at CMakeLists.txt:28 (find_package):
  By not providing "FindKF5KIO.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "KF5KIO", but
  CMake did not find one.
  Could not find a package configuration file provided by "KF5KIO" (requested
  version 5.4) with any of the following names:
    KF5KIOConfig.cmake
    kf5kio-config.cmake
  Add the installation prefix of "KF5KIO" to CMAKE_PREFIX_PATH or set
  "KF5KIO_DIR" to a directory containing one of the above files.  If "KF5KIO"
  provides a separate development package or SDK, be sure it has been
  installed.
Then
$ wajig install libkf5newstuff-dev
$ cmake
[…]
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find KF5 (missing: Activities) (found version "5.68.0")
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/ECM/find-modules/FindKF5.cmake:110 (find_package_handle_standard_args)
  CMakeLists.txt:30 (find_package)
And finally
$ wajig install libkf5activities-dev
After that it works correctly!
ksokoban.png