Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cross Compiling with CMake
QtWS25 Last Chance

Cross Compiling with CMake

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 6.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mistralegnaM Offline
    mistralegnaM Offline
    mistralegna
    wrote on last edited by mistralegna
    #1

    Hi !

    I would like to cross compile a Qt application using CMake from Linux to target a Windows platform. I installed successfully the mingw32 compiler on Linux, and I precised in the CMakeLists file to use this compiler instead of the well known g++, by setting the CMake variable CMAKE_CXX_COMPILER to x86_64-w64-mingw32-g++.

    Unfortunately, although the cmake $src work fine, the compilation fails totally, by reporting this error :

    /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1: error adding symbols: File in wrong format

    I suppose the link with the Qt libraries doesn't match the expected Qt libraries for Windows build but the Linux ones.

    I googled a solution to do this cross compilation but I didn't find anything relevant.

    Could anyone please inform me on the way to perform this cross compilation using CMake ?

    Thanks a lot !

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The first thing you would have to do is cross-compile Qt with that compiler. Then you can recompile your application using that version of Qt

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • mistralegnaM Offline
        mistralegnaM Offline
        mistralegna
        wrote on last edited by mistralegna
        #3

        Thanks for your fast answer.

        In fact, I tried yesterday to compile Qt with that compiler, using :

        ./configure -xplatform win32-g++ -device-option CROSS_COMPILE=x86_64-w64-mingw32- (is that correct ?)

        but I have the following errors :

        Warning: Disabling pkg-config since PKG_CONFIG_LIBDIR is not set.
        Warning: Disabling pkg-config since PKG_CONFIG_SYSROOT_DIR is not set.
        STL functionality check failed! Cannot build Qt with this STL library.

        It seems the two first lines are just warnings but the last line is an error.

        I suppose I am not setting some variables when configuring Qt, but I have no idea what are the two first variables PKG_CONFIG_LIBDIR and PKG_CONFIG_SYSROOT_DIR.

        I tried this :

        PKG_CONFIG_LIBDIR=/usr/x86_64-w64-mingw32/lib ./configure -xplatform win32-g++ -device-option CROSS_COMPILE=x86_64-w64-mingw32- -sysroot /usr/x86_64-w64-mingw32

        but I still have the same error about the STL.

        Thanks a lot for your help !

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you restart configure from a clean state ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • mistralegnaM Offline
            mistralegnaM Offline
            mistralegna
            wrote on last edited by
            #5

            Hello !

            Indeed, I was trying to compile the dirty sources.

            But now I can go to the sudo make install step, and I have the following error :

            ${somewhere}/qtbase/include/QtCore/../../src/corelib/global/qt_windows.h:63:21:
            

            Here is what I did :

            tar -xzf qt-everywhere-opensource-src-5.4.0.tar.gz
            cd qt-everywhere-opensource-src-5.4.0
            PKG_CONFIG_LIBDIR=/usr/x86_64-w64-mingw32/lib ./configure -v -xplatform win32-g++ -device-option CROSS_COMPILE=x86_64-w64-mingw32- -sysroot /usr/x86_64-w64-mingw32
            make -j 4
            sudo make install
            

            Have I missed something ?

            Thanks a lot for your help, it seems I'm close to the joy of cross-compiling, thanks to you !

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              What's the error you are getting ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • mistralegnaM Offline
                mistralegnaM Offline
                mistralegna
                wrote on last edited by
                #7

                I haven't see the lack of the error above.

                Here is the complete line with the error :

                /home/gabriel/qt-everywhere-opensource-src-5.4.0/qtbase/include/QtCore/../../src/corelib/global/qt_windows.h:63:21: fatal error: windows.h: No such file or directory
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Are you sure you have that header installed on your computer ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • mistralegnaM Offline
                    mistralegnaM Offline
                    mistralegna
                    wrote on last edited by
                    #9

                    Yes, the header windows.h is installed.

                    dpkg -S windows.h
                    output >> mingw-w64-x86-64-dev: /usr/x86_64-w64-mingw32/include/windows.h
                    dpkg -l mingw-w64-x86-64-dev
                    output >> ii  mingw-w64-x86-64-dev (.*)
                    ls -ltr /usr/x86_64-w64-mingw32/include/windows.h
                    ...  /usr/x86_64-w64-mingw32/include/windows.h -> ../../share/mingw-w64/include/windows.h
                    

                    and I precise to the configure script usr/x86_64-w64-mingw32 as sysroot.

                    Perhaps I missed an option of the configure script ?

                    Thanks a lot for your help, because I have to go on Windows to compile my Qt application for Windows, unfortunately, and I would like to have not.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Try adding (with the space)

                      -I /usr/x86_64-w64-mingw32/include/

                      to your configure call.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • mistralegnaM Offline
                        mistralegnaM Offline
                        mistralegna
                        wrote on last edited by
                        #11

                        I already tried this, and I had this error :

                        /usr/x86_64-w64-mingw32/include/malloc.h:209:18: error: expected declaration before end of line
                        

                        Thanks a lot for your help !

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved