3

I'm trying to build a cross-platform QT C++ application (Linux/Windows), using MXE and cmake. I googled very, very hard, you don't know how brilliant my google queries were. Such queries. But:

The problem: undefined references.

/home/user/mxe/usr/i686-w64-mingw32.static/qt5/lib/libQt5Core.a(qregularexpression.o):qregularexpression.cpp:(.text+0x2b7): undefined reference to `pcre16_exec'

(and many others of this kind)

The solution:

cd ~/mxe && make pcre

then add to CMakeFiles.txt:

ADD_LIBRARY(pcre STATIC IMPORTED)
SET_TARGET_PROPERTIES(pcre PROPERTIES IMPORTED_LOCATION /home/user/mxe/usr/i686-w64-mingw32.static/lib/libpcre16.a)
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME} pcre)

Final problem: Other Undefined References.

/home/user/mxe/usr/i686-w64-mingw32.static/qt5/lib/libQt5Core.a(qbytearray.o):qbytearray.cpp:(.text+0x60a): undefined reference to `uncompress'
/home/user/mxe/usr/i686-w64-mingw32.static/qt5/lib/libQt5Core.a(qbytearray.o):qbytearray.cpp:(.text+0x1a30): undefined reference to `compress2'
/home/user/mxe/usr/i686-w64-mingw32.static/qt5/lib/libQt5Gui.a(qharfbuzzng.o):qharfbuzzng.cpp:(.text+0x143e): undefined reference to `hb_font_funcs_set_glyph_v_origin_func'

But I don't know from what library this compress or hb_font_funcs_set_glyph_v_origin_func comes. I could google them one by one, but it looks like a stone age practice. And in a long perspective I don't want to do this for every cross-compiled project.

The question(s):

How do I find names of needed libraries, without reading qt build files? Is there a way to output dependencies (dynamic libraries needed) using cmake or make?

Possible solutions:

  • I know I can use ldd on a binary file. What I need is something like link-time ldd. Is this possible?

  • Maybe I could use make (during QT building stage) to print QT's dependencies. If so, how to do it?

UPD: discovered

  • mxe related almost solution:

    usr/bin/i686-w64-mingw32.static-pkg-config --list-all | sort

    usr/bin/i686-w64-mingw32.static-pkg-config Qt5Widgets --libs

Community
  • 1
  • 1
strangeqargo
  • 1,276
  • 1
  • 15
  • 23
  • You don't need to do any of that. Use the cmake module provided by Qt: it will link your target with all necessary libraries that Qt itself depends on. This should be very simple - the work is already done, you only have to reuse it. – Kuba hasn't forgotten Monica Nov 23 '16 at 22:54
  • I have `find_package( Qt5Core REQUIRED ) find_package( Qt5Widgets REQUIRED ) find_package( Qt5Gui REQUIRED ) #find_package( Qt5Qml REQUIRED )` and `find_package(Qt5 COMPONENTS Core Widgets Gui Network)` and `qt5_use_modules( ${CMAKE_PROJECT_NAME} Core Widgets Gui )`, but mxe's cmake should find them by default I guess - and it founds them, it can't find dependencies. (It builds ok in Linux if it can help) – strangeqargo Nov 23 '16 at 23:12
  • 1
    I guess your main problem is that you are attempting a static build, thus you need the statically built version of some or all of the libraries Qt itself is using. pcre for the regular expressions, compress/uncompress from zlib, the hb_ function from Harfbuzz. Maybe build a dynamically linked version once and then use ldd to find all dependencies? – Kevin Krammer Nov 24 '16 at 10:12

0 Answers0