Visual Studio Setup for Maya 2014 and QT

The following is the culmination of a lot of detective work and trial and error on my part. My goal, which I thought rather simple, was to setup Visual Studio 2010 Express to compile plug-ins for Maya. Turns out this is simple, right up until you involve QT. Detailed below are the steps taken to make this happen.

 

Visual Studio 2010 Express

Note about Windows 8.1

Setting up this build environment in Windows 8.1 takes a bit more work than Windows 7. The primary issue is that 8.1 comes with .NET 4.5 which prevents the install of Windows SDK 7.1. A healthy bit of experimentation and internet searching (thanks to everyone in this thread on Mathworks) resulted in a successful installation. I have never experienced this problem when setting up Visual Studio 2010 (non-express version) in Windows 7. So if you’re on 7 and haven’t installed .NET 4.5 you might not need to follow these steps to the letter.

Software Installation

Start by uninstalling the following:

  • Uninstall any Visual Studios, redistributions, compilers, service packs, etc.
  • Uninstall any .NETs.
  • Uninstall any Windows SDKs.

Once you’ve purged your system go ahead and reboot. We start by installing Windows SDK 7.1, but due to this issue with Visual Studio SP1 we need to follow specific steps. Otherwise we’ll end up with the x64 compilers and library files being removed from Visual Studio.

  1. Download Windows SDK 7.1 (download link)
  2. Install the SDK. During the installation in “Installation Options” uncheck “Microsoft Visual C++ 2010” component.
  3. Download and apply the Windows SDK 7.1 SP1 (download link)
  4. Download and install the Microsoft Visual C++ 2010 redistributable packages
    1. x64 (download link)
    2. x86 (download link)
  5. Download and install Visual Studio 2010 Express (download link)
  6. Download and install Visual Studio 2010 SP1 (download link)

 

QT 4.8.2 Build

I’m going to let Autodesk explain why we need to build QT.

Maya uses a customized version of Nokia’s Qt libraries. If you want to write Maya plug-ins which also make use of Qt you will have to build Qt from the modified source files provided in this directory and link your plug-ins against those libraries.

Build Preparation

Download the correct QT source files from Autodesk. The Maya 2014 zip is called “QT 4.8.2 for Maya and MotionBuilder 2014.” (download link)

Extract the zip file contents as follows:

Create a folder called “qt” where ever you want the source files to live. For my examples I’ll be using C:\.

ex. C:\qt\

Create a folder called “openssl-1.0.1c” in your QT folder.

ex. C:\qt\openssl-1.0.1c

Open the file openssl_1_0_1c.zip and extract the contents of “1.0.1c” into your “openssl-1.0.1c” folder.

Create a folder called “4.8.2-64.”

ex. C:\qt\4.8.2-64

Open the file qt-adsk-4.8.2.tgz and extract the contents of “qt-adsk-4.8.2” into your “4.8.2-64” folder.

QT Build Folders

Build

To build QT start by opening a Visual Studio x64 Command Prompt. If you’re in Windows 8.1 then you’ll want to open Windows SDK 7.1 Command Prompt.

Windows SDK 64 PromptNavigate to your QT folder:

cd \qt\4.8.2-64

Run the following command to begin the build process (warning, it’s a multi-parter!):

configure -debug-and-release -no-qt3support -openssl -plugin-sql-sqlite -I C:\qt\openssl-1.0.1c\include -L C:\qt\openssl-1.0.1c\x64

When prompted type “o” and hit Enter.

When prompted type “y” and hit Enter.

When this part is finished type “nmake” in the command prompt and hit Enter. This one will take ages to complete. I’m serious. Go do something else because it will take hours. When the make has finished all that’s left is to install it. In the command prompt type:

nmake install

 

Visual Studio Setup

Create a Solution

Open Visual Studio and create an Empty Project.

vs_setup_001

In the Solution Explorer right-click and choose Properties.

vs_setup_001_1

Click on Configuration Manager… in the upper right corner.

vs_setup_002

The New Solution Platform window will appear. Change the platform to x64 and Copy settings from to <Empty>. Click OK and close the Configuration Manager.

vs_setup_003

Apply the changes and close the solution property pages dialog.

vs_setup_004

Project Setup

I created an example plug-in and uploaded the files to a Google Code project. They can be grabbed here. Put them in your VS project folder.

vs_setup_006

The following are the project settings that you’ll need to use. Be sure to apply them to both release and debug! If you do this before adding any source files to the project then the C/C++ properties won’t show up. Just add a .CPP file and re-open the property pages.

Any directory path should be changed to reflect your specific locations.

  • General
    • Target Extension: .mll
    • Platform Toolset: Windows7.1SDK
    • Configuration Type: Dynamic Library (.dll)
  • Debugging
    • Command: C:\Program Files\Autodesk\Maya2014\bin\maya.exe
  • VC++ Directories
    • Include Directories: .;C:\Program Files\Autodesk\Maya2014\include;C:\Program Files\Autodesk\Maya2014\Qt Includes
    • Library Directories: C:\qt\4.8.2-64\lib;c:\Program Files (86)\Microsoft Visual Studio 10.0\VC\lib\amd64;c:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;c:\Program Files\Autodesk\Maya2014\lib
  • C/C++
    • General
      • Additional Include Directories: .;C:\Program Files\Autodesk\Maya2014\include;C:\Program Files\Autodesk\Maya2014\Qt Includes
    • Preprocessor
      • _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;WIN32;NDEBUG;_WINDOWS;NT_PLUGIN;REQUIRE_IOSTREAM
  • Linker
    • General
      • Additional Library Directories: C:\qt\4.8.2-64\lib;c:\Program Files (86)\Microsoft Visual Studio 10.0\VC\lib\amd64;c:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;c:\Program Files\Autodesk\Maya2014\lib
    • Input
      • Additional Dependencies: Foundation.lib;OpenMaya.lib;OpenMayaUI.lib;OpenMayaAnim.lib;OpenMayaFX.lib;OpenMayaRender.lib;Image.lib;QtCore4.lib;QtGui4.lib;QtUiTools.lib
    • Command Line
      • Additional Options: /export:initializePlugin /export:uninitializePlugin

Makefiles, Bat files and the Devil – or – Building the Plug-in

I say the Devil because from this point onward was nothing but trouble. I was on there were build errors whose error messages were so vague as to be near useless. Eventually I worked out the kinks, but before getting into that I suggest reading up on the how’s and why’s of building a Maya plug-in with QT.

Makefiles

In the Google Code project you’ll find three makefiles – Makefile.at, qtconfig and test_command.pro. These files are modified versions of the examples provided by Autodesk (C:\Program Files\Autodesk\Maya2014\devkit\plug-ins).

Place them in the directory with the source files.

Makefile.qt

Makefile.qt has one line that will need tweaked when building different plug-ins. Change it to match the name of you plug-in.

qtconfig

Qtconfig defines a whole mess of directory paths. These will need update to match your specific system.

qtplugin.pro

Uncomment this line if you want to build the plug-in in debug.

Specifics of the plug-in are assigned here. If you need to add/remove headers, sources, forms or resources this is the spot to do that.

QT UI Files

Like the others, these are in the Google Code project. They consist of:

  1. test_command.ui is the UI created with QT Designer.
  2. qtplugin.qrc is an XML file that lists the files associated with the UI. Read more about them here.

Building the Plug-in with Batch Files

Building the plug-in is as simple as running a few commands in a command prompt. To make life easier I put together some batch files to do this for me.

.UI Header Batch

We need to generate a C++ header file for our test_command.ui and include it in our plug-in’s header file. To do this create text file called ‘ui.bat‘ in your source folder and copy/paste the below text into the file. Make any path changes and then run the file. It will generate a new header called ui_test_command.h in your source folder.

Build Clean Batch

This batch file doesn’t create files or do any building. Instead it deletes files generated during the build process.

Create a text file called ‘clean_build.bat‘ in your source folder and copy/paste the below text into the file. Be sure to make any path changes.

Build Release Batch

Builds a release version of the plug-in. You’ll notice that I used Windows short path names. I was running into problems with the build crapping out because of spaces in the path.

Create a text file called ‘release_build.bat‘ in your source folder and copy/paste the below text into the file. Be sure to make any path changes.

Build Debug Batch

Builds a debug version of the plug-in. You’ll need to run the release batch file first to generate the required files for a debug build. Specifically the .mak.debug file. Remember that file called qtplugin.pro I mentioned earlier? Before you run this batch file be sure to uncomment the config line that enables debugging.

Also prior to building a debug version you’ll need to edit the qtplugin.mak.debug file. Maya doesn’t support the use of QT debug libraries. Using them will result in a crash when the command is executed. To do this open the file and search for the following LIBs and remove the ‘d‘ from their name.

  1. QtXmld4.lib
  2. QtGuid4.lib
  3. QtCored4.lib
  4. QtUiToolsd.lib

Create a text file called ‘debug_build.bat‘ in your source folder and copy/paste the below text into the file. Be sure to make any path changes.

Environment Variables

A quick comment on Windows environment variables. I have the following set to PATH. You may or may not need to do this.

  1. C:\qt\4.8.2-64\bin
  2. C:\PROGRA~1\MICROS~2\Windows\v7.1\Bin\x64
  3. C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64\

Test It!

Assuming all goes well you should be able to build the example plug-in. To test, load it in Maya and type ‘qtTest;’ in a MEL Script Editor window. A lot of work went into this post, all of which is worth while if it helps even one technical artist avoid the frustrations I went through.

Maya Plugin UI