Can't Compile Test Qt-Widget(Static) Locally

by ADMIN 45 views

Introduction

In this article, we will explore the issue of compiling a Qt-Widget(Static) project using xmake, a cross-platform build utility based on Lua. The project is unable to compile, despite the presence of a statically linked Qt library, which has been verified to be correct using CMake or xmake. We will delve into the error logs and provide a solution to this problem.

Xmake Version

The version of xmake being used is v3.0.0+dev.2774ecb.

Operating System and Architecture

The operating system being used is Archlinux, and the architecture is x86_64.

Description of the Problem

The project in question is xmake/tests/projects/qt/widgetapp_static, which is unable to compile using xmake. However, there are no errors when using CMake or xmake, indicating that the statically linked Qt library is correct. The issue lies in xmake's ability to pass its own test.

Expected Result

The expected result is to be able to compile the project successfully.

Project Configuration

The project configuration is as follows:

add_rules("mode.debug", "mode.release")

includes("@builtin/qt")

target("demo")
    add_rules("qt.widgetapp_static")
    add_headerfiles("src/*.h")
    add_files("src/*.cpp")
    add_files("src/mainwindow.ui")
    add_files("src/mainwindow.h")
    add_frameworks("QtSvg")
    qt_add_static_plugins("QSvgPlugin", {linkdirs = "plugins/imageformats", links = {"qsvg"}})

Additional Information and Error Logs

The error logs are too long to be included in this article, but they can be found in the attached file error.log. The preview of the error logs is as follows:

sgct@MokkaShip in repo: xmake/tests/projects/qt/widgetapp_static on  dev +/- via  as 🧙
⬢ [debian]   ❯ xmake f --qt=/usr/local/Qt-5.15.16/
checking for platform ... linux
checking for architecture ... x86_64
checking for Qt SDK directory ... /usr/local/Qt-5.15.16
checking for Qt SDK version ... 5.15.16

sgct@MokkaShip in repo: xmake/tests/projects/qt/widgetapp_static on  dev +/- via  as 🧙
⬢ [debian]   ❯ xmake -vD
checking for Qt SDK directory ... /usr/local/Qt-5.15.16
checking for Qt SDK version ... 5.15.16
[ 25%]: compiling.qt.ui src/mainwindow.ui
/usr/local/Qt-5.15.16/bin/uic src/mainwindow.ui -o build/.gens/demo/linux/x86_64/release/rules/qt/ui/ui_mainwindow.h
checking for gcc ... /usr/bin/gcc
checking for the c++ compiler (cxx) ... gcc
checking for /usr/bin/gcc ... ok
checking for flags (-fPIC) ... ok
> gcc "-fPIC" "-m64"
checking for flags (-fvisibility-inlines-hidden) ... ok
> gcc "-fvisibility-inlines-hidden" "-m64checking for flags (-O3) ... ok
> gcc "-O3" "-m64"
checking for flags (-DNDEBUG) ... ok
> gcc "-DNDEBUG" "-m64"
checking for flags (-fPIC) ... ok
> gcc "-fPIC" "-m64"
[ 37%]: compiling.qt.moc src/mainwindow.h
/usr/local/Qt-5.15.16/bin/moc -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_SVG_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DQT_CORE_LIB -Ibuild/.gens/demo/linux/x86_64/release/platform/windows/idl -I/home/sgct/Downloads/xmake/tests/projects/qt/widgetapp_static/build/.gens/demo/linux/x86_64/release/rules/qt/ui -I/usr/local/Qt-5.15.16/include/QtSvg -I/usr/local/Qt-5.15.16/include/QtSvg/5.15.16 -I/usr/local/Qt-5.15.16/include/QtSvg/5.15.16/QtSvg -I/usr/local/Qt-5.15.16/include/QtGui -I/usr/local/Qt-5.15.16/include/QtGui/5.15.16 -I/usr/local/Qt-5.15.16/include/QtGui/5.15.16/QtGui -I/usr/local/Qt-5.15.16/include/QtWidgets -I/usr/local/Qt-5.15.16/include/QtWidgets/5.15.16 -I/usr/local/Qt-5.15.16/include/QtWidgets/5.15.16/QtWidgets -I/usr/local/Qt-5.15.16/include/QtCore -I/usr/local/Qt-5.15.16/include/QtCore/5.15.16 -I/usr/local/Qt-5.15.16/include/QtCore/5.15.16/QtCore -I/usr/local/Qt-5.15.16/include -I/usr/local/Qt-5.15.16/mkspecs/linux-g++ src/mainwindow.h -o build/.gens/demo/linux/x86_64/release/src/moc_mainwindow.cpp
/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++11 -Ibuild/.gens/demo/linux/x86_64/release/platform/windows/idl -I/home/sgct/Downloads/xmake/tests/projects/qt/widgetapp_static/build/.gens/demo/linux/x86_64/release/rules/qt/ui -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_SVG_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DQT_CORE_LIB -isystem /usr/local/Qt-5.15.16/include/QtSvg -isystem /usr/local/Qt-5.15.16/include/QtSvg/5.15.16 -isystem /usr/local/Qt-5.15.16/include/QtSvg/5.15.16/QtSvg -isystem /usr/local/Qt-5.15.16/include/QtGui -isystem /usr/local/Qt-5.15.16/include/QtGui/5.15.16 -isystem /usr/local/Qt-5.15.16/include/QtGui/5.15.16/QtGui -isystem /usr/local/Qt-5.15.16/include/QtWidgets -isystem /usr/local/Qt-5.15.16/include/QtWidgets/5.15.16 -isystem /usr/Qt-5.15.16/include/QtWidgets/5.15.16/QtWidgets -isystem /usr/local/Qt-5.15.16/include/QtCore -isystem /usr/local/Qt-5.15.16/include/QtCore/5.15.16 -isystem /usr/local/Qt-5.15.16/include/QtCore/5.15.16/QtCore -isystem /usr/local/Qt-5.15.16/include -isystem /usr/local/Qt-5.15.16/mkspecs/linux-g++ -DNDEBUG-fPIC -o build/.objs/demo/linux/x86_64/release/gens/src/moc_mainwindow.cpp.o build/.gens/demo/linux/x86_64/release/src/moc_mainwindow.cpp
[ 50%]: cache compiling.release src/main.cpp
/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++11 -Ibuild/.gens/demo/linux/x86_64/release/platform/windows/idl -I/home/sgct/Downloads/xmake/tests/projects/qt/widgetapp_static/build/.gens/demo/linux/x86_64/release/rules/qt/ui -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_SVG_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DQT_CORE_LIB -isystem /usr/local/Qt-5.15.16/include/QtSvg -isystem /usr/local/Qt-5.15.16/include/QtSvg/5.15.16 -isystem /usr/local/Qt-5.15.16/include/QtSvg/5.15.16/QtSvg -isystem /usr/local/Qt-5.15.16/include/QtGui -isystem /usr/local/Qt-5.15.16/include/QtGui/5.15.16 -isystem /usr/local/Qt-5.15.16/include/QtGui/5.15.16/QtGui -isystem /usr/local/Qt-5.15.16/include/QtWidgets -isystem /usr/local/Qt-5.15.16/include/QtWidgets/5.15.16 -isystem /usr/local/Qt-5.15.16/include/QtWidgets/5.15.16/QtWidgets -isystem /usr/local/Qt-5.15.16/include/QtCore -isystem /usr/local/Qt-5.15.16/include/QtCore/5.15.16 -isystem /usr/local/Qt-5.15.16/include/QtCore/5.15.16/QtCore -isystem /usr/local/Qt-5.15.16/include -isystem /usr/local/Qt-5<br/>
# Can't Compile Test Qt-Widget(Static) locally: Q&A

## Q: What is the issue with compiling the Qt-Widget(Static) project using xmake?

A: The issue lies in xmake's inability to pass its own test, despite the presence of a statically linked Qt library, which has been verified to be correct using CMake or xmake.

## Q: What is the expected result of compiling the project?

A: The expected result is to be able to compile the project successfully.

## Q: What is the project configuration?

A: The project configuration is as follows:
```lua
add_rules("mode.debug", "mode.release")

includes("@builtin/qt")

target("demo")
    add_rules("qt.widgetapp_static")
    add_headerfiles("src/*.h")
    add_files("src/*.cpp")
    add_files("src/mainwindow.ui")
    add_files("src/mainwindow.h")
    add_frameworks("QtSvg")
    qt_add_static_plugins("QSvgPlugin", {linkdirs = "plugins/imageformats", links = {"qsvg"}})

Q: What are the error logs indicating?

A: The error logs are indicating that there are undefined references to certain functions, such as png_get_io_ptr and png_error. This suggests that there is an issue with the linking of the Qt library.

Q: How can I resolve the issue with the linking of the Qt library?

A: To resolve the issue with the linking of the Qt library, you can try the following:

  • Check that the Qt library is correctly installed and configured.
  • Verify that the QT_LIBS variable is set correctly in the project configuration.
  • Try adding the QT_LIBS variable to the linkflags option in the project configuration.
  • Check that the QT_INCLUDES variable is set correctly in the project configuration.
  • Verify that the QT_INCLUDES variable is included in the includes option in the project configuration.

Q: What are some common issues that can cause the linking of the Qt library to fail?

A: Some common issues that can cause the linking of the Qt library to fail include:

  • Incorrect installation or configuration of the Qt library.
  • Missing or incorrect QT_LIBS variable.
  • Missing or incorrect QT_INCLUDES variable.
  • Incorrect linkflags option in the project configuration.
  • Incorrect includes option in the project configuration.

Q: How can I troubleshoot the issue with the linking of the Qt library?

A: To troubleshoot the issue with the linking of the Qt library, you can try the following:

  • Check the error logs for any clues about the issue.
  • Verify that the Qt library is correctly installed and configured.
  • Check that the QT_LIBS variable is set correctly in the project configuration.
  • Verify that the QT_INCLUDES variable is set correctly in the project configuration.
  • Try adding the QT_LIBS variable to the linkflags option in the project configuration.
  • Try adding the QT_INCLUDES variable to the includes option in the project configuration.

Q: What are some best practices for compiling Qt projects using xmake?

A: Some best practices for compiling Qt projects using xmake include:

  • Verify that the Qt library is correctly installed and configured.
  • Check that the QT_LIBS is set correctly in the project configuration.
  • Verify that the QT_INCLUDES variable is set correctly in the project configuration.
  • Use the linkflags option to specify the linking flags for the Qt library.
  • Use the includes option to specify the includes for the Qt library.
  • Use the qt_add_static_plugins option to add static plugins to the project.
  • Use the qt_add_frameworks option to add frameworks to the project.