Showing posts with label QT. Show all posts
Showing posts with label QT. Show all posts

Friday, March 22, 2013

QT-Creator 2.6 with Intel Compiler

Recently i started developing a heavy-calculations application, which required iMKL, so that i decided to use Intel  C++ Composer as well, both in Linux and in Windows. I also decided to use QT-creator as my primary IDE for GUI development, although i kept using other IDE-s (VS, Eclispe) for tests.

1) Linux experience: 

I used OpenSuSE 12.3, that comes with  qt4-devel v 4.8.4 and qtcreator 2.6 packages. Intel says that it does not support opensuse, and installer refuses to work, so a little override is required. How to install Intel Composer 2013 on OpenSuSE 12.3
1) unpack the Intel Composer (or Parallel Studio), and go into the unpacked distribution folder
2) edit  silent.cfg file -- set the correct serial number or license information, set INSTALL_MODE=RPM
3) run  ./install --silent silent.cfg
4) If you use Eclipse CDT, dont forget to add Intel Integrations for Eclipse CDT (here)

Open Qt-Creator,
1) open Menu -> Tools -> Options -> Build&Run -> Compilers press "Add" and select "Linux ICC".
2) go to "Kits" options tab, select the default "Desktop" toolkit, press "Clone",
3) set its compiler to the ICC selected from above
4) set mkspecs filename to linux-icc

now the helloworld should build and run, and GDB should work as debugger. At least it stops on breakpoints. 

2) Windows experience - with Visual Studio: 

You are supposed to have VisualStudio in order to use Intel C++ Composer. So far I tested with VS 2012.  Also, my application was 64bit only, and, for compatibility reasons, i decided to stick with QT-4.8.4. 

It could work with pre-compiled Qt-4.8 built with vs2010, but since i needed 64bit application, i had to compile it myself. Open the according 64-bit VisualStudio compiler command prompt, go to QT sources and build them as usual: 

configure -prefix C:/install/path 
nmake
nmake install 

Now you need to setup an Intel toolchain within QtCreator. For some reason it does not allow it to do in GUI, so a trick is required. 
1. Go to Menu-> Parameters-> Build and Run -> Compilers
2. Select the according VS compiler, the same you used to compile your QT with. and press "Clone" button. Rename the new compiler toolchain. 
3. We will need to change it's path to initialization .bat file, but the GUI does not allow to do it, and we have to do it manually in config files. Open the file Explorer and go to  %AppData%\QtProject\qtcreator  folder (just copy-paste it into address bar) and open the toolchains.xml file with your favorite editor. It is an XML file that consist of ... entries. Find the entry which correponds to the toolchain copy  that you created previously. (Normally, It should be the one with the largest ToolChain.N number.) And replace the     <value key="ProjectExplorer.MsvcToolChain.VarsBat" type="QString"> and  <value key="ProjectExplorer.MsvcToolChain.VarsBatArg" type="QString"> lines with the following values: 

   <value key="ProjectExplorer.MsvcToolChain.VarsBat" type="QString">c:\Program Files (x86)\Intel\Composer XE\bin\compilervars.bat</value>
   <value key="ProjectExplorer.MsvcToolChain.VarsBatArg" type="QString">intel64 vs2012shell</value>

See the compilervars.bat itself for details. Note, that you should set the VarsBatArgs value according to you compiler version and platform. 

3. Create a new "Toolkit".
Go to Menu->Parameters->Kits 
Add the one you have, if it is still absent. It is configured to work with the same compiler that was used to build it. Now press the "Duplicate" button, and rename the new option for your convenience. In its properties change the compiler to the intel toolchain, created previously, and set mkspecs option to win32-icc

Now select this toolkit in the project properties. The sample helloworld project should compile and run just fine. However, it is possible, that the debugger is still not working - it never stops on breakpoints. To fix this go to QT installation folder and open the mkspecs/win32-icc/qmake.conf file. 
find the   QMAKE_CFLAGS_DEBUG = -Zi -MDd -O2  line, and change -O2 parameter to -Od so that it looks like: 

QMAKE_CFLAGS_DEBUG = -Zi -MDd -Od  

(UPD: seems like the latest versions already have this fixed)

So now the debugging should work as well, at least it stops on breakpoints!.


3) Visual Studio Express Edition notes:

 If you only have Visual Studio Express edition , you may encounter "Visual Studio is not found in the system" error when launching Intel 64 command prompt from Start menu. It is said that Express Edition does not support the Composer integration, so we only can use the Command Prompt to build applications. That is OK with me since i wanted to use QtCreator for development.

For most cases see:  http://software.intel.com/en-us/articles/error-visual-studio-2005-2008-or-2010-is-not-found-in-the-system-when-launching-intel-64

I have only Visual Studio 2012 Express edition for Windows Desktop, so I did the following:

1) locate compilervars_arch.bat file in  c:\Program Files (x86)\Intel\Composer XE\bin\  and open it for editing.
2)
locate the following strings:

::VS2012
if /i "%TARGET_VS%"=="vs2012" (
  if defined VS110COMNTOOLS (
    if exist "%VS110COMNTOOLS%..\IDE\devenv.exe" (
      if exist "%VS110COMNTOOLS%..\..\VC\vcvarsall.bat" (
         set MSVS_VAR_SCRIPT="%VS110COMNTOOLS%..\..\VC\vcvarsall.bat"
         goto Calls
      )
    )

and promptly after them add the following:

    if exist "%VS110COMNTOOLS%..\IDE\WDExpress.exe" (
      if exist "%VS110COMNTOOLS%..\..\VC\vcvarsall.bat" (
         set MSVS_VAR_SCRIPT="%VS110COMNTOOLS%..\..\VC\vcvarsall.bat"
         if /i "%TARGET_ARCH%"=="intel64" set TARGET_VS_ARCH=x86_amd64
echo "VS 2012 express for Desktop found"
         goto Calls
      )
    )

just before the if exist "%VS110COMNTOOLS%..\IDE\VSWinExpress.exe"  string. 

Wednesday, January 30, 2008

Visual C++ 2005 project using QT and qmake

Recently, one may find lots of rumours about future acvisition of Trolltech by Nokia.
I would'nt worry much about it. QT is GPL, and that means, we will always have it around.

Recently, i started some QT development, and previously i was doing it in my favorite OpenSuSE environment, using KDevelop 3.5. Untill I started to do some really hardcore programming, utilizilng lost of BOOST and Computational Geometry (CGAL). I found out, that Visual C++ 2005 has more comfortable Debugger, so i decided to switch my development back to Windows XP (thanx to MSDN AA) and VC++ 2005.

As you might already know, the "official"OpenSource version of QT/Windows supports only MinGW GCC, which sucks. Previously, one had to use some magick patches (here is an instruction: how to patch QT to work with Visual C++ 2005) . Last time i tried to use them, i had non-working binaries in "Release" configuration. But the salvation came unexpectedly from KDE project, with their release of KDE for Windows.

The KDE for Windows itself is not much usefull -- there is no Desktop Environment yet, only some Applications available. Its biggest value is ... the Libraries!!!! and, of cource.. QT! wich supports VC2005 natively, witouht further patching. Here is small 1-2-3 how to start developing QT OpenSource apps in windows:

1) use Kde Windows Installer to install QT, and other libs that you might need (Boost? image handling libs? eigen? libz ? whatever...)
2) Get VC++ 2005 Express Edition (Kde installer may also help)

say, you have installed everything to D:\KDE, then i recommend to save it as Windows Environment variable (say, QTHOME) -- may be handy for team development, and stuff.
Now you are ready to create a "Hello world" app.

1) Open VisualStudio, create a new "Makefile" project. (Figure 1)


2) it will prompt for "build" "rebuild" and "clean" commands for Debug and Release configurations. For these i create 6 different custom .bat files, and specify them on prompt.



Your solution dir now has "helloworld" subdir. There we'll have to create several files:

main.cpp: (add it to the VS project as "source file")
#include
#include
#include

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton hello("Hello world!");
hello.resize(100, 30);
hello.show();
return app.exec();
}


helloworld.pro
-- the QMake project file
SOURCES += main.cpp
TEMPLATE = app
CONFIG += warn_on thread qt stl
TARGET = helloworld
FORMS +=
HEADERS +=
INCLUDEPATH +=


build_debug.bat
qmake
nmake Debug

rebuild_debug.bat
clean_debug.bat build_debug.bat
clean_debug.bat
qmake nmake clean

now copy the last three into build_release.bat, rebuild_release.bat and clean_release.bat accoordingly, replacing "Debug" into "Release". you may add them into the VC project, for example, into another project subfolder, for later convininent modifications.



now you may press the "Build Solution" button, and see what happens.
the last two things remain:
1) Debugger. You need to specify the executable.


2) Intellisense. You need to specify the includepaths for QT and other libs.


Now, you may check at the QPushButton hello object how it works.


The last step: i used kde-installer 0.8.5 which installed QT 4.3.3. For some reason, the makefiles, created with QMAKE did not create the moc_- files.
i had lots of errors like:
moc_mainwindow.cpp
c1xx : fatal error C1083: Cannot open source file: 'debug\moc_mainwindow.cpp': N
o such file or directory
moc_mainview.cpp
c1xx : fatal error C1083: Cannot open source file: 'debug\moc_mainview.cpp': No
such file or directory



To fix this, i had to manually rewrite my qt.conf, which resides in the bin directory of KDE installation.
for example, if you have installed KDE into D:\KDE, then you'd have to create/edit the file
D:\KDE\bin\qt.conf:
[Paths]
Prefix=D:\\KDE\\
Documentation=D:\\KDE\\doc
Headers=D:\\KDE\\include
Libraries=D:\\KDE\\lib
Binaries=D:\\KDE\\bin
Plugins=D:\\KDE\\plugins
Data=D:\\KDE\\
Translations=D:\\KDE\\translations
Settings=D:\\KDE\\etc
Examples=D:\\KDE\\examples
Demos=D:\\KDE\\demos





that's all, folks! Happy Hacking!