Results 1 to 5 of 5

Thread: How build Qt with CMake & MinGW in windows?

  1. #1
    Join Date
    Nov 2014
    Posts
    6
    Thanks
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Question How build Qt with CMake & MinGW in windows?

    I make a test project, and uploaded to github: https://github.com/Jennal/QtCmake

    It works fine in MacOSX, but failed to link in Windows.

    Errors are:
    Qt Code:
    1. Linking CXX executable HelloCMakeQt.exe
    2. CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj):(.text+0x91): undefined reference to `_imp___ZNK7QWidget4sizeEv'
    3. CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj):(.text+0x22d): undefined reference to `_imp___ZNK11QMouseEvent3posEv'
    4. CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj):(.text+0x27f): undefined reference to `_imp___ZNK11QMouseEvent1xEv'
    5. CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj):(.text+0x28c): undefined reference to `_imp___ZNK6QPoint1xEv'
    6. CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj):(.text+0x2a5): undefined reference to `_imp___ZNK11QMouseEvent1yEv'
    7. CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj):(.text+0x2b2): undefined reference to `_imp___ZNK6QPoint1yEv'
    8. CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj):(.text+0x2cb): undefined reference to `_imp___ZNK11QMouseEvent7buttonsEv'
    9. CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj):(.text+0x351): undefined reference to `_imp___ZNK11QMouseEvent7buttonsEv'
    10. CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj):(.text+0x400): undefined reference to `_imp___ZNK11QMouseEvent3posEv'
    11. C:\msys64\mingw32\bin\ld.exe: CMakeFiles\HelloCMakeQt.dir/objects.a(main.cpp.obj): bad reloc address 0x8 in section `.text[__ZN10MainWindowD2Ev]'
    12. clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
    13. CMakeFiles\HelloCMakeQt.dir\build.make:295: recipe for target 'HelloCMakeQt.exe' failed
    14. mingw32-make[2]: *** [HelloCMakeQt.exe] Error 1
    15. CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/HelloCMakeQt.dir/all' failed
    16. mingw32-make[1]: *** [CMakeFiles/HelloCMakeQt.dir/all] Error 2
    17. Makefile:136: recipe for target 'all' failed
    18. mingw32-make: *** [all] Error 2
    To copy to clipboard, switch view to plain text mode 

    I googled for days and can't find any solution. Can someone help me?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,389
    Thanks
    247
    Thanked 688 Times in 678 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How build Qt with CMake & MinGW in windows?

    You may have to add a preprocessor define "QT_DLL" to tell the compiler and linker that you are using Qt libraries as DLLs. This causes the Windows-specific __declspec( dllimport ) and __declspec( dllexport ) macros to be defined, which in turn modifies the mangled names of the classes and methods in the Qt header files so they match the exports from the DLLs.

    I am not familiar enough with CMake to tell you how to add an environment-specific preprocessor define.

  3. The following user says thank you to d_stranz for this useful post:

    jennal (15th December 2014)

  4. #3
    Join Date
    Nov 2014
    Posts
    6
    Thanks
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How build Qt with CMake & MinGW in windows?

    Thank you for your reply.

    I found that failed because I compile some library with STATIC option, and Qt is linked with SHARED by default. Then I download Qt source code and compile to STATIC with help of the document: http://qt-project.org/wiki/How-to-bu...-Windows-MinGW

    And I success to build the exe file. But still failed to launch. When I launch the exe, it shows an error message:

    Qt Code:
    1. This application failed to start because it could not find or load the Qt platform plugin "windows".
    2.  
    3. Reinstalling the application may fix this problem.
    To copy to clipboard, switch view to plain text mode 

    Then a runtime error message:

    Qt Code:
    1. Runtime Error!
    2.  
    3. Program:
    4. C:\Path\HelloQt.exe
    5.  
    6. This application has requested the Runtime to terminate it in an unusual way.
    7. Please contact the application's support team for more information.
    To copy to clipboard, switch view to plain text mode 

    Any idea of this issue?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How build Qt with CMake & MinGW in windows?

    Qt needs a couple of plugins to work. If you use Qt built statically, you need to build the plugins statically and link those plugins explicitly with your application. The docs page on "Static Plugins" should help you with that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    jennal (15th December 2014)

  7. #5
    Join Date
    Nov 2014
    Posts
    6
    Thanks
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How build Qt with CMake & MinGW in windows?

    @wysota Thank you for your help. I will solve this by myself then.

Similar Threads

  1. CMake fails on Windows 7 64-bit
    By IndigoJo in forum Qt Programming
    Replies: 5
    Last Post: 12th September 2011, 21:15
  2. CMake and Qt on Windows using MinGW
    By woodtluk in forum General Discussion
    Replies: 1
    Last Post: 26th December 2010, 19:04
  3. Build Libtorrent By Mingw windows 7
    By nhs_0702 in forum Qt Programming
    Replies: 3
    Last Post: 5th April 2010, 23:16
  4. build project with cmake does not work
    By codebehind in forum Qt Programming
    Replies: 4
    Last Post: 18th August 2008, 12:29
  5. Qt with cmake on windows xp
    By Ashish in forum Newbie
    Replies: 1
    Last Post: 6th October 2006, 22:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.