File: windows_native_port.rst

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (278 lines) | stat: -rw-r--r-- 10,507 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
Windows native port
===================

The previous section explained how to cross-build OpenTURNS from Linux
to target Windows. This section gives hints in order to compile
OpenTURNS natively with Microsoft Windows tools. This port has started
since OpenTURNS 1.4 and is still in an early stage, any help from
developers who are familiar with Windows environment will be greatly
appreciated.

These instructions have been tested with Visual Studio 2010 on Windows
32 and 64 bits, but they should work with more recent versions too.
Visual Studio Express Edition does not ship 64 bits compilers, but they
can be installed from Windows SDKs, instructions can be easily found
online. No Fortran compiler is required.

Automatic compilation
---------------------

First of all, CMake must be installed, as well as C/C++ compilers. We
will describe below how to use CMake with Visual Studio and Microsoft
compilers, but CMake can also be used with other build systems (like
NMake, for instance) and other compilers, see CMake documentation for
further details.

The following programs are required in order to build on Windows:

-  `OpenBLAS <https://github.com/xianyi/OpenBLAS/>`_ (or any other BLAS
   implementation)

The following programs are optional, and we will show how to embed them:

-  `Boost <https://www.boost.org/>`_

-  `LibXML2 <http://www.xmlsoft.org/>`_

-  `TBB <https://www.threadingbuildingblocks.org/>`_

-  `hmat-oss <https://github.com/jeromerobert/hmat-oss/>`_

If you want to recompile them from sources, you may also have to install

-  `Git <http://git-scm.com/>`_

Installation layout
~~~~~~~~~~~~~~~~~~~

In this tutorial, dependencies are installed by following the
layout shown in figureĀ [fig:win-inst-layout]. Below the top-level
directory are four configurations (Debug and Release for Windows 32 bits
or 64 bits). Of course, if you are only interested by a single
configuration, there is no need to create others. Each configuration
contains subdirectories for Boost, hmat-oss, LibXML2, OpenBLAS
and TBB programs. Each project contains one or several directories:
``bin`` for DLLs, ``include`` for header files, and ``lib`` for static
libraries.

.. figure:: Figures/win_native/win-inst-layout.png
   :alt: Windows installation layout

   Windows installation layout

For convenience, all libraries will be compiled as static libraries,
except OpenBLAS.

Build and install OpenBLAS and TBB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For different reasons, OpenBLAS and TBB cannot be compiled along with
other dependencies. As explained on their site, OpenBLAS is currently
only supported on Windows with Mingw compiler. But binaries can be used
with Visual Studio, this is what we will do. Thus go to
http://sourceforge.net/projects/openblas/files/ and download Windows
binaries, for instance
``OpenBLAS-v0.2.13-Win32.zip`` for Windows 32 bits, or
``OpenBLAS-v0.2.13-Win64-int32.zip`` for Windows 64 bits.

Unzip these archives, and copy files to our installation folder:

-  | ``OpenBLAS-x.y-Win32\bin\libopenblas.dll`` into
     ``Win32-Release\openblas\bin\`` and
   | ``Win32-Debug\openblas\bin\``

-  | ``OpenBLAS-x.y-Win32\lib\libopenblas.dll.a`` into
     ``Win32-Release\openblas\lib\`` and
   | ``Win32-Debug\openblas\lib\``

-  | ``OpenBLAS-x.y-Win32\include`` into ``Win32-Release\openblas\`` and
   | ``Win32-Debug\openblas\``

-  | ``OpenBLAS-x.y-Win64-int32\bin\libopenblas.dll`` into
     ``Win64-Release\openblas\bin\`` and
   | ``Win64-Debug\openblas\bin\``

-  | ``OpenBLAS-x.y-Win64-int32\lib\libopenblas.dll.a`` into
     ``Win64-Release\openblas\lib\`` and
   | ``Win64-Debug\openblas\lib\``

-  | ``OpenBLAS-x.y-Win64-int32\include`` into
     ``Win64-Release\openblas\`` and
   | ``Win64-Debug\openblas\``

Note that DLLs have been compiled with Mingw, and require some Mingw
runtime libraries. They can be found in
http://sourceforge.net/projects/openblas/files/v0.2.12/mingw32_dll.zip
and
http://sourceforge.net/projects/openblas/files/v0.2.12/mingw64_dll.zip.
They are:

-  ``libgcc_s_sjlj-1.dll``, ``libgfortran-3.dll`` and
   ``libquadmath-0.dll`` for Win32

-  ``libgcc_s_seh-1.dll``, ``libgfortran-3.dll`` and
   ``libquadmath-0.dll`` for Win64

TBB comes with its own Visual Studio 2010 configuration file, but we did
not find how to integrate it into the build system described below. Thus
the easiest solution is to:

#. Download TBB sources from
   https://www.threadingbuildingblocks.org/download

#. Unpack it.

#. Launch ``build\vs2010\makefile.sln``

#. Select ``Win32`` or ``x64`` architecture, and ``Release`` or
   ``Debug`` configuration (not ``Release-MT`` or ``Debug-MT``, unless
   you know what you are doing).

#. If you want to build a static library, edit Properties, tab
   Configuration Properties, General, Configuration Type, as shown in
   figureĀ [fig:vs-tbb-static]

#. Build project.

#. Copy resulting libraries into installation folder:

   -  ``build\vs2010\ia32\Debug\tbb_debug.lib`` into
      ``Win32-Debug\tbb\lib\``

   -  ``build\vs2010\ia32\Release\tbb.lib`` into
      ``Win32-Release\tbb\lib\``

   -  ``build\vs2010\intel64\Debug\tbb_debug.lib`` into
      ``Win64-Debug\tbb\lib\``

   -  ``build\vs2010\intel64\Release\tbb.lib`` into
      ``Win64-Release\tbb\lib\``

#. | Copy ``include\tbb`` folder into installation folders:
     ``Win32-Debug\tbb\include``,
   | ``Win32-Release\tbb\include``, ``Win64-Debug\tbb\include`` and
     ``Win64-Release\tbb\include``.

.. figure:: Figures/win_native/vs-tbb-static.png
   :alt: Visual Studio settings to build tbb as a static library

   Visual Studio settings to build tbb as a static library

Build and install
~~~~~~~~~~~~~~~~~

OpenBLAS and TBB are low level libraries. Other libraries use STL, and
care must be taken to avoid mismatch between runtime libraries. To this
end, we decided to use a so called *SuperBuild* approach with CMake. We
defined a metaproject which drives compilation of those dependencies,
and also of OpenTURNS itself. Clone `ot-superbuild git repository
<https://bitbucket.org/dbarbier/ot-superbuild>`_ (or download an archive
from this URL), launch ``cmake-gui`` program, and follow the following
steps:

#. Launch ``cmake-gui``, and select source and build directories

.. figure:: Figures/win_native/cmake-gui-start.png

#. Click on button. Select a generator (either Visual Studio 10 or
   Visual Studio 10 Win64) and compiler

.. figure:: Figures/win_native/cmake-gui-compiler.png

#. For Win64, CMake may give an error about missing 64-bit tools, as in
   snapshot below. Visual Studio Express Edition does not embed 64-bit
   compilers, and CMake thus checks whether we are using Express Edition
   or not.

.. figure:: Figures/win_native/cmake-gui-error.png

   It seems that this detection is sometimes buggy; if you know that
   64-bit compilers are available, you can workaround this automatic
   detection by clicking on button, adding a ``CMAKE_GENERATOR_TOOLSET``
   variable, of type ``STRING``, and value ``v100``.

.. figure:: Figures/win_native/cmake-gui-toolset.png

#. Click on button again, everything should work fine now, and output
   window should display ``Configuring done``.

#. Now that CMake has checked that our compiler is working fine, we can
   tell it where to find OpenBLAS and TBB. Set ``OPENBLAS_INCLUDE_DIR``,
   ``OPENBLAS_LIBRARY``, ``TBB_INCLUDE_DIR`` and ``TBB_LIBRARY``
   variables, as shown below:

.. figure:: Figures/win_native/cmake-gui-superbuild.png

   and click on button.

#. If everything went fine, click on button. This generates Visual
   Studio solution files in the specified build directory, and you can
   now close ``cmake-gui`` window.

#. Launch ``openturns-superbuild`` solution file.

.. figure:: Figures/win_native/vs-superbuild.png

   Select ``Release`` or ``Debug`` configuration (it must match TBB
   configuration), and build solution file. This will download sources
   (a working Internet connection is thus required), unpack and build
   them. It can take a long time on a slow machine, or with a slow
   Internet connection, since some downloaded sources are large.

#. Copy ``build64\ExternalProjects\Install\*`` directories into
   installation prefix (``OT1.5\Win64-Release\``, or ``Win32-Release``,
   etc)

Manual compilation
------------------

If you want to modify settings, the simplest solution is to proceed as
in previous section, and modify Visual Studio settings afterwards.
Dependencies are downloaded, built and installed into an
``ExternalProjects`` subdirectory of build directory, ie
``build64\ExternalProjects`` in our example. This directory contains the
following folders:

-  ``Build``: contains generated Visual Studio projects, and files
   generated during builds

-  ``Download``: contains project archives

-  ``Install``: after build, each project installs resulting files
   (header files and libraries) there

-  ``Source``: unpacked source files

-  ``Stamp``: keeps track of already processed steps

-  ``tmp``

Each directory in turn contains one directory per project. Thus if one
wants to modify some settings when compiling OpenTURNS, one has to go to
``build64\ExternalProjects\Build\openturns\`` directory and launch the
Visual Studio solution file found there, in this case ``OpenTURNS.sln``.
For instance, one can build OpenTURNS tests from this solution file.
Beware to always check that active configuration is the desired one.

Troubleshooting
---------------

-  It is possible to build multiple configurations with Visual Studio
   solution files, but this is currently not supported by our
   ``CMakeLists.txt`` files; thus one must launch ``cmake-gui``, adapt
   variables (for instance paths to OpenBLAS and TBB libraries must be
   modified for each configuration) and press and buttons.

-  No OpenBLAS library in ``Debug`` mode is provided, but the one from
   ``Release`` mode works also in ``Debug`` mode. On the other hand,
   OpenTURNS and TBB configurations must match, it is not possible to
   link OpenTURNS in ``Debug`` mode against TBB in ``Release`` mode, or
   vice-versa.

-  Boost contains files with very long filenames, which causes trouble
   on NTFS. If you have already built Boost and want to build it again,
   Visual Studio may complain that it encountered an error when building
   it again. In that case, launch file explorer and remove Boost
   directory, then press again button of CMake (because some of its
   generated files had been removed too), it should now build fine.