Freitag, 14. Oktober 2011

Qt 4.7.4 and Visual Studio 2010 Integration

How to integrate Qt 4.7.4 in Visual Studio 2010 (32bit/64bit).

// i rewrote this howto for my mind but most of it comes from here (thanks)

My environment:
Assuming you have at least:
  • Visual Studio 2010 (not the express edition :P)
    (i will not cover alternative ways (mingw g++) here, but if you have tuts on it, let me know.)
  • on windows xp it should work but tell me if not (with error description of course :))
  • ServicePack 1 for Visual Studio 2010
    if link doesnt work, google for visual studio 2010 service pack and download the web installer
    if i recall download size was beyond 500MB
  • maybe this patch is still needed for vs2010 (only if u go for x64)

How to:
  1. extract qt source to dir (i'll use C:\Qt\4.7.4)

  2. setup path in system environment variables
    - add new variable QTDIR with path to source (C:\Qt\4.7.4)
    - edit variable PATH and insert "%QTDIR%\bin;"
    - add variable QMAKESPEC="win32-msvc2010" (works also for 64bit)

  3. start command prompt from visual studio tools:
    (it's a normal cmd with further environment vars for compiling)
    - there are several command prompt files:
    - 32bit: take the normal command prompt without any additions
    (I have "Visual Studio-Eingabeaufforderung (2010)" here :) )

    - 64bit: compiling take "...x64 Win64"
    ("Eingabeaufforderung von Visual Studio x64 Win64 (2010)" in german version)

    // if you do not really need 64bit i will recommend 32 bit
    // if you want both you perhaps have to create another dir such as Qt\4.7.4_64bit\

  4. type in that command console
    $ cd %QTDIR%
    $ configure -shared -debug-and-release -opensource -opengl desktop -platform win32-msvc2010 -no-qt3support -no-webkit -mp -no-phonon -no-phonon-backend
    $ nmake

    // -mp = multiple processors for compiling with MSVC (-MP) // so you dont need "jom"
    // -platform win32-msvc2010 works also for 64bit if you took VS2010 x64 console
    // Qt Libs are compiled as 64bit then

  5. compiling is done, now go for visual studio add-in (i have v1.1.9)
    - install it :)

  6. run vs2010 and set qt dir in Qt -> Qt Options (C:\Qt\4.7.4)

NOTE: configure for static libs
if you want static libs running configure -static ... you will get a very big output (30gigs and more) because examples and demos will compiled as static (bigger exes). unfortunately you cannot disable compiling examples and demo by configure argument as you may know from linux (-nomake examples ...). you could disable compiling by modifying pro files respectively or you dont care cuz you have enough space. you also can clean the examples and demos afterwards by moving into these directories and run "nmake clean."

Note: 64bit Qt and OpenGL ("libgles32.lib" linker error)
If you have compiled on x64 you will get a linker error in Qt OpenGL based projects because of a "bug". Linker additional dependencies point to a "libgles32.lib". Well, we are not on an embedded system so remove this and insert opengl32.lib instead of it.
(Project Properties and Linker and then Input and Additional Dependencies if i translated it correct.)

Note: 64bit Qt Libs
You cannot create 32bit qt projects of course. Linking against x64 compiled Qt Libs will fail.

Note: Enabling 64bit compiling in VS2010
Project Properties and Configurations Manager (top right button). Create a new configuration and choose x64.

Note: Qt GUI with forms and Console for debug output (qDebug, printf, etc)
Project Properties and Linker and System and change SubSystem to Console (GUI will work though).

Keine Kommentare:

Kommentar veröffentlichen