Build Occt With Msvs Express

This page is part of the Tutorial Started by D. Semikin.

Building OCCT660 With MSVS 11 Express for Desktop Development

NOTE: Previous version of similar post about building OCCT655 is moved here: temporary-name-0001-old.

To start learning OCCT I first have to get it working, so I will build it from sources (together with required 3-rd party libraries).

Get OCCT Source Distribution

As we want to build OCCT660 with MSVS 11 Express, first of all we should download them. It seems that for both of these products only the latest version is available for download from the official sites. This time (April 28, 2013) OCCT660 and MSVS11 (2012) Express are current versions.

Go to msdn.com, search for MSVS express and download/install available version.

Go to opencascade.org, register there (it is necessary to be able to download distribution), go to download section and download *.tar.gz file.

After downloading source archive I extracted them to the directory "D:\Libs\OCCT\OpenCASCADE660". And I set environment variable %OcctDir% to point to this dir:

set OcctDir=D:\Libs\OCCT\OpenCASCADE660

Either I set standard %casroot% environment variable to point to "ros" dir within %OcctDir%:

set CASROOT=%OcctDir%\ros

Building 3rd Party Dependencies

Documentation related to build and list of needed 3rd party packages.

When start building something, it is good idea to read available documentation about prerequisites and the build process. And I already know, that OpenCASCADE depends on 3-rd party libraries. So I will start with building it. There are two places dedicated to building of 3-rd party libraries for OpenCASCADE. Those are

Of course I start with the official document, which tells us, that following items are totally required:

  • Tcl 8.5,
  • Tk 8.5,
  • FreeType 2.4.10,

and optional items:

  • TBB 3.x or 4.x,
  • gl2ps 1.3.5,
  • FreeImage 3.14.1,

With the help of links provided in that document or Google I could easily locate where those packages can be downloaded.

NOTES:

  1. Although in the list of required packages Tcl/Tk of version 8.5 is listed, later it is written, that it is possible to use either 8.6 version. Besides, that document tells that we should use binaries build by ActiveState, but I'd like to build them myself, so I will download them from [[tcl.tk]] and do the build (see below).
  2. At this moment (April 28, 2013) only TBB 4.1 Update 3 is available for download. I'm not sure, I will use it as it looks as it is optional. On the site there is binaries package for windows, which contains binaries for all versions of visual studio.

If we look at [[[|]]], then we will see, that we need either GNU Make (to build FreeType) and CMake (to build GL2PS). I downloaded installer of CMake from official site [and as I have perl (from ActiveState) installed, I'd like to try to use [[http://makepp.sourceforge.net|make++].

Finally, I decieded to use latest versions of all libraries because I hoped, that they will be better compatible with latest version of MSVC.

After downloading and extracting packages I had the following content of my 3rd-parties directory (I manually added version to FreeImage dir):

28.04.2013  02:03    <DIR>          ARCHIVES
28.04.2013  02:01    <DIR>          FreeImage-3.15.4
28.04.2013  01:44    <DIR>          freetype-2.4.11
28.04.2013  02:02    <DIR>          gl2ps-1.3.8-source
28.04.2013  01:39    <DIR>          makepp-2.0.98.3
28.04.2013  01:45    <DIR>          tbb41_20130314oss
28.04.2013  01:48    <DIR>          tcl8.6.0
28.04.2013  01:48    <DIR>          tk8.6.0

This is the listing of directory "D:\Libs\OCCT\3rd_parties_660" and I will set environment variable %OccThirdParties% for it

set OccThirdParties=D:\Libs\OCCT\3rd_parties_660

Building Tcl 8.6

For details on building Tcl with nmake see comments in the beginning of the file "%OccThirdParties%\win\makefile.vc".

REM  File: %OccThirdParties%\01_build_tcl.cmd

set OccThirdParties=%cd%

call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"

cd tcl8.6.0\win
nmake -f makefile.vc release
nmake -f makefile.vc install INSTALLDIR=%OccThirdParties%\tcl8.6.0-install
cd ..\..

Building Tk 8.6

For details on building Tk with nmake see "%OccThirdParties%\win\makefile.vc".

REM  File: %OccThirdParties%\02_build_tk.cmd

set OccThirdParties=%cd%

call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"

cd tk8.6.0\win

REM  I'm not sure about 8.6 but with Tk 8.5 it was required to point to "build
REM  directory" of Tcl, but not "installation directory" with TCLDIR option.
nmake -f makefile.vc TCLDIR=%OccThirdParties%\Tcl8.6.0 release

REM  For some reason this make file ignores trailing dir of the INSTALLDIR,
REM  so we add "dummy" dir at the end.
nmake -f makefile.vc install TCLDIR=%OccThirdParties%\Tcl8.6.0 INSTALLDIR=%OccThirdParties%\tk8.6.0-install\dummy
cd ..\..

Building FreeType 2.4.11

I did not manage to build it with make++ (I did not try too hard), so I fall back to build and use GNU make instead, as described in other page of this wiki: Building 3rd party libraries and tools.

For details on building see "%OccThirdParties%\freetype-2.4.11\docs\INSTALL.GNU"

REM  File: %OccThirdParties%\03_build_freetype.cmd

set OccThirdParties=%cd%

call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"

set path=%path%;%OccThirdParties%\make-3.82\WinDebug

cd freetype-2.4.11
make setup visualc
make

cd ..

Building gl2ps 1.3.8

Build as described in official PDF file from OpenCASCADE (building 3-rd parties on windows).

I build as it is recommended in CMake usage guidelines in separate directory "%OccThirdParties%\gl2ps-1.3.8-build".

While configuring in CMake GUI (or command line) don't forget to disable ZLIB, PNG and change CMAKE_INSTALL_PATH as appropriate (I set it to "%OccThirdParties%\gl2ps-1.3.8-install", so you can find this path in further scripts).

CMake configuration output:

Could NOT find GLUT (missing:  GLUT_glut_LIBRARY GLUT_INCLUDE_DIR) 
Configuring done

But anyway it built then successfully in Visual Studio (not tried to use it yet).

Note, that after building "ALL_BUILD" project one should build either "INSTALL" project to install output to the install dir, which was set up during CMake configuration.

Actually, one can not do "INSTALL" step, then she/he just have to set up include dir to corresponding directory within "sources" dir and "lib" and "bin" dirs. to corresponding directories within "build" dir, which is IMHO less convenient (besides, I don't know, possibly, INSTALL step perform some additional adjustments… - I did not check it).

Building FreeImage 3.15.4

Go to directory "%OccThirdParties\FreeImage-3.15.4" and open file FreeImage2008.sln in visual studio.

Convert it as proposed.

When start building projects FreeImage and FreeImagePlus failed to build because they lack file "afxres.h".

This file is part of MFC and MFC is not supplied with Express version of MSVS. So we have do install Windwos Driver Development Kit (WinDDK).

In my case it installed by default into C:\WinDDK.

So, I opened "Properties" windows for FreeImage, go to Configuration Properties\Resoruces\General and add to "Additional include directories" directory "C:\WinDDK\7600.16385.1\inc\mfc42".

Then do same thing for FreeImagePlus (of course for all required configurations.

Then build again. Now it succeeds.

Installing TBB 4.1

Just extract downloaded file "tbb41_20130314oss_win.zip". it seems, that resulting dir contains all required binaries for all versions of vc (including vc11).

Build OpenCASCADE660

To, those, who are not so experienced with windows cmd scripts: "%~dp0" refers to the directory in which current cmd script is located (I teems, that trailing back slash "\" is present.

Modification of scripts to setup build environment

When I look into %CASROOT% directory, I found there four .cmd scripts:

  • custom.bat
  • draw.bat
  • env.bat
  • msvc.bat

"draw.bat" is used for starting DRAWEXE.exe application, when OpenCASCADE is already built so, we do not need it right now. Note, that it uses "env.bat" (and consequently "custom.bat" - see below) to setup the same environment as used for building by "msvc.bat"

"msvc.bat" is used to setup environment variables and open MSVC with solution to build OpenCASCADE. I look inside it and see the following things:

  • It already have support for MSVS 11 Express (OCCT 655 did not have corresponding option in this file).
  • It uses "env.bat" inside it.

So we conclude, that we do not need to change anything in this script.

"env.bat" is script, which sets up the environment. I can see, that it uses "custom.bat" inside. So I guess, I do not need to change anything within this script, but within "custom.bat" instead.

Indeed, "custom.bat" looks like file, in which system dependent paths are set (although, there is no comment in this regard in the file itself). So I adjust this file to meet my system. Here is the result:

(Note, that as I set default values for toolchain, platform and configuration, I do not have to explicitly pass them to "msvc.bat" script)

@echo off
REM  FILE: %CASROOT%\custom.bat

REM  I will set default platform to which I will use mostly, i.e. to vc11, win32, Debug
set VCVER=vc11
set ARCH=32
set "VCVARS=%VS110COMNTOOLS%..\..\VC\vcvarsall.bat"
set "PRODUCTS_PATH=%~dp0..\..\3rd_parties_660"
REM  Original settings:
REM set VCVER=vc9
REM set ARCH=32
REM set "VCVARS=%VS90COMNTOOLS%..\..\VC\vcvarsall.bat"
REM set "PRODUCTS_PATH=%~dp0..\..\3rd_parties_660"

rem Optional 3rd-parties switches
set HAVE_FREEIMAGE=true
set HAVE_GL2PS=true
set HAVE_TBB=true
REM  set CHECK_QT4=true
REM  set CHECK_JDK=true

REM  I will use Qt later, but it seems, that we do not need it to build
REM  "something special" we do not need to rebuild anything (to "add support
REM  for Qt") to use Qt with OpenCASCADE then. So for now I disable this.
set CHECK_QT4=false

REM  I do not have JDK and will not use Java (at least for now).
set CHECK_JDK=false

rem Additional headers search paths
set "CSF_OPT_INC=%PRODUCTS_PATH%\tcl8.6.0-install\include"
set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\tk8.6.0-install\include"
set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\freetype-2.4.11\include"
set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\FreeImage-3.15.4\Dist"
set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\FreeImage-3.15.4\Wrapper\FreeImagePlus\Dist"
set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\gl2ps-1.3.8-install\include"
set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\tbb41_20130314oss\include"
REM  I do not need those, as I do not use Qt and Java for now
REM  set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\qt462-vc9-32\include"
REM  set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\qt462-vc9-32\include\Qt"
REM  set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\qt462-vc9-32\include\QtGui"
REM  set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\qt462-vc9-32\include\QtCore"
REM  set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\jdk1.6.0-32\include"
REM  set "CSF_OPT_INC=%CSF_OPT_INC%;%PRODUCTS_PATH%\jdk1.6.0-32\include\win32"

rem Additional libraries (32-bit) search paths
set "CSF_OPT_LIB32=%PRODUCTS_PATH%\tcl8.6.0-install\lib"
set "CSF_OPT_LIB32=%CSF_OPT_LIB32%;%PRODUCTS_PATH%\tk8.6.0-install\lib"
set "CSF_OPT_LIB32=%CSF_OPT_LIB32%;%PRODUCTS_PATH%\freetype-2.4.11\objs"
set "CSF_OPT_LIB32=%CSF_OPT_LIB32%;%PRODUCTS_PATH%\FreeImage-3.15.4\Dist"
set "CSF_OPT_LIB32=%CSF_OPT_LIB32%;%PRODUCTS_PATH%\FreeImage-3.15.4\Wrapper\FreeImagePlus\dist"
set "CSF_OPT_LIB32=%CSF_OPT_LIB32%;%PRODUCTS_PATH%\gl2ps-1.3.8-install\lib"
set "CSF_OPT_LIB32=%CSF_OPT_LIB32%;%PRODUCTS_PATH%\tbb41_20130314oss\lib\ia32\vc11"
REM  I do not need this now as I do not use Qt
REM  set "CSF_OPT_LIB32=%CSF_OPT_LIB32%;%PRODUCTS_PATH%\qt462-vc9-32\lib"

REM  I do not need those below, because I build 32-bit version
rem Additional libraries (64-bit) search paths
REM  set "CSF_OPT_LIB64=%PRODUCTS_PATH%\tcltk-85-64\lib;%PRODUCTS_PATH%\freetype-2.4.10-vc9-64\lib;%PRODUCTS_PATH%\freeimage-vc9-64\lib;%PRODUCTS_PATH%\gl2ps-1.3.5-vc9-64\lib;%PRODUCTS_PATH%\tbb30_018oss\lib\intel64\vc9;%PRODUCTS_PATH%\qt462-vc9-64\lib"

rem Additional (32-bit) search paths
set "CSF_OPT_BIN32=%PRODUCTS_PATH%\tcl8.6.0-install\bin"
set "CSF_OPT_BIN32=%CSF_OPT_BIN32%;%PRODUCTS_PATH%\tk8.6.0-install\bin"
REM  There is no .dll in my freetype build. Possibly it will be linked
REM  statically.
REM  set "CSF_OPT_BIN32=%CSF_OPT_BIN32%;%PRODUCTS_PATH%\freetype-2.4.11\???"
set "CSF_OPT_BIN32=%CSF_OPT_BIN32%;%PRODUCTS_PATH%\FreeImage-3.15.4\Dist"
set "CSF_OPT_BIN32=%CSF_OPT_BIN32%;%PRODUCTS_PATH%\FreeImage-3.15.4\Wrapper\FreeImagePlus\dist"
REM  Note, that .dll is located in "lib" dir for gl2ps
set "CSF_OPT_BIN32=%CSF_OPT_BIN32%;%PRODUCTS_PATH%\gl2ps-1.3.8-install\lib"
set "CSF_OPT_BIN32=%CSF_OPT_BIN32%;%PRODUCTS_PATH%\tbb41_20130314oss\bin\ia32\vc11"
REM  I do not need two below as I do not use Qt and Java for now.
REM set "CSF_OPT_BIN32=%CSF_OPT_BIN32%;%PRODUCTS_PATH%\qt462-vc9-32\bin"
REM set "CSF_OPT_BIN32=%CSF_OPT_BIN32%;%PRODUCTS_PATH%\jdk1.6.0-32\bin"

REM  I do not need those below, because I build 32-bit version
rem Additional (64-bit) search paths
REM  set "CSF_OPT_BIN64=%PRODUCTS_PATH%\tcltk-85-64\bin;%PRODUCTS_PATH%\freetype-2.4.10-vc9-64\bin;%PRODUCTS_PATH%\freeimage-vc9-64\bin;%PRODUCTS_PATH%\gl2ps-1.3.5-vc9-64\bin;%PRODUCTS_PATH%\tbb30_018oss\bin\intel64\vc9;%PRODUCTS_PATH%\qt462-vc9-64\bin;%PRODUCTS_PATH%\jdk1.6.0-64\bin"

NOTES:

  1. As I set default values for platform (win32) and tool chain (vc11), I do not need to supply them to "msvc.bat" script explicitly.
  2. I did not change names of libraries produced for third parties, so it is expected, that there will be link errors. I will have to rename lib files or to adjust project properties to resolve those.

Now I've done configuration for build and can start it. It will take some time. Let's see, how it will go…

Fixing the MSVC solution to make it buildable

Indeed, there were link errors to FreeImage.lib. So I decided not to bother myself with changing the project properties and just rename FreeImaged.lib to FreeImage.lib. And start build process again which effectively only link the projects.

After rebuild more errors arose.

One of these are conflict between "libcmt.lib" and "msvcr11d.lib" while linking TKService. To fix this problem I disabled linkage of "libcmt.lib" in TKService properties: Configuration Properties\Linker\Input -> Ignore specific default libraries.

TKDraw: Cannot open "tcl85.lib". To fix it open TKRraw's properties and modify "Configuration Properties\Linker\Input -> Additional Dependencies": Change "tcl85.lib" to "tkl86t.lib" and "tk85.lib" to tk86t.lib" i.e. to those available in tcl-install and tk-install dirs.

TKOpenGL: Cannot open "FreeImagePlus.lib". To fix this change TKOpenGL properties in the same place (In Debug configuration) to link "FreeImagePlusd.lib". ??? For some reason TKOpenGL does not explicitly link FreeImagePlus.lib??? So, to solve this problem I just renamed FreeImagePlusd.lib to FreeImagePlus.lib.

TKViewerTest, TKQADraw: Cannot open "tcl85.lib": Fix: same as for TKDraw

After these fixes restarted build finished successfully. I was able to start DRAWEXE.exe, but on start it showed following message in the console:

tkLoop: error in Tk initialization. Tcl reported: Can't find a usable tk.tcl in the following directories:
D:/Libs/OCCT/3rd_parties_660/tcl8.6.0-install/lib/tcl8.6/tk8.6 D:/Libs/OCCT/3rd_parties_660/tcl8.6.0-install/lib/tk8.6 
D:/Libs/OCCT/OpenCASCADE660/ros/adm/msvc/vc11/./../../../win32/vc11/lib/tk8.6
D:/Libs/OCCT/OpenCASCADE660/ros/adm/msvc/vc11/./../../../win32/lib/tk8.6
D:/Libs/OCCT/OpenCASCADE660/ros/adm/msvc/vc11/./../../../win32/vc11/library

But still, "pload ALL" finished without errors (and loaded lots of stuff). And I was able to successfully execute (to execute DRAWEXE.exe right-click on DRAWEXE project and select "set as startup project". Then Press "F5" key or click "Debug" button):

axo
box b 200 300 400
fit
r
r
r
u
u
u

with desired effect.

So, at this point I think, that OpenCASCADE build is finished successfully.


This page is part of the Tutorial Started by D. Semikin.