# Building Debug on Window

**URL:** https://discourse.kitware.com/t/building-debug-on-window/770
**Category:** Build & Install
**Created:** [February 4, 2022, 10:16pm UTC](https://discourse.kitware.com/t/building-debug-on-window/770 "2022-02-04T22:16:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Stan\_Hammon](https://discourse.kitware.com/user_avatar/discourse.kitware.com/stan_hammon/32/487_2.png) [@Stan\_Hammon](https://discourse.kitware.com/u/Stan_Hammon)
#### Post date: [February 4, 2022, 10:16pm UTC](https://discourse.kitware.com/t/building-debug-on-window/770/1 "2022-02-04T22:16:51Z")

</div>

# General Setting

My goal is to build `smtk` (and later, `cmb`) in `Debug`. The problem is that `cmb-superbuild` does not allow `Debug` builds.

To work around this limitation, I want to build `cmb-superbuild` in `RelWithDebugInfo`, while also setting:

- `/MDd /DWIN32` compiler flags
- `_ITERATOR_DEBUG_LEVEL=0` (in the downstream projects, not `cmb-superbuild`)

As I understand it, this should allow the subsequent build of `smtk` to be `Debug`, even though `smb-superbuild` is built in `RelWithDebInfo`.

# Steps Taken

## `_ITERATOR_DEBUG_LEVEL`

The command line argument `-D_ITERATOR_DEBUG_LEVEL=0` does not seem to work, and instead the following line needs to be added to the main `CMakeLists.txt` file:

```auto
add_definitions(-D_ITERATOR_DEBUG_LEVEL=0)

```

It is unclear to me so far whether it is better to:

1. set `_ITERATOR_DEBUG_LEVEL=2` in `cmb-superbuild`, or
2. set `_ITERATOR_DEBUG_LEVEL=0` in `smtk` (and later, `cmb`)

I have not yet had a chance to test these two options.

## `/MDd /DWIN32` compiler flags

These compiler flags are set using these `cmake` commands:

```auto
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MDd /DWIN32")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /DWIN32")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MDd /DWIN32")

```

The `/MDd` does not seem to propagate, and so must be set at every level of `cmb-superbuild`. So far, these lines of code are added to:

- CMakeLists.txt
- projects\paraview.cmake
- projects\vtk.cmake
- projects\vtkonly.cmake
- projects\win32\moab.cmake
- superbuild\projects\win32\boost.cmake

# Problem

For most parts of `cmb-superbuild`, the above steps work well. However, this fails for `VTK` within `paraview`. Specifically, we get hundreds/thousands of compile errors like:

```auto
cl : Command line warning D9025 : overriding '/MDd' with '/MD' 

```

I cannot find any other likely locations where I should insert the compiler flags definitions to get past these compile errors.

How can I prevent `paraview` from overriding my specified flags?

---

<div class="post-metadata">

### Author: ![Stan\_Hammon](https://discourse.kitware.com/user_avatar/discourse.kitware.com/stan_hammon/32/487_2.png) [@Stan\_Hammon](https://discourse.kitware.com/u/Stan_Hammon)
#### Post date: [February 4, 2022, 10:17pm UTC](https://discourse.kitware.com/t/building-debug-on-window/770/2 "2022-02-04T22:17:27Z")

</div>

@ben.boeckel Can you take a look at this?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.kitware.com/u/ben.boeckel)
#### Post date: [February 6, 2022, 4:52pm UTC](https://discourse.kitware.com/t/building-debug-on-window/770/3 "2022-02-06T16:52:48Z")

</div>

> [@Stan\_Hammon](#):
>
> `/DWIN32`

This is pointless. Don’t set it. It is really spelled `_WIN32` and is set by any sensible compiler. Anything relying on `WIN32` should be fixed.

> [@Stan\_Hammon](#):
>
> The command line argument `-D_ITERATOR_DEBUG_LEVEL=0` does not seem to work

Why would it? That sets a CMake variable (about which nothing cares about).

> [@Stan\_Hammon](#):
>
> These compiler flags are set using these `cmake` commands:

MSVC runtime is now selected by the [`MSVC_RUNTIME_LIBRARY`](https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html) property. Do not set it via flags manually. Instead, you can use the `CMAKE_MSVC_RUNTIME_LIBRARY` variable. Note that projects which are not aware of CMake 3.15 will ignore this. We should make these projects CMP0091-aware instead.

> [@Stan\_Hammon](#):
>
> However, this fails for `VTK` within `paraview`. Specifically, we get hundreds/thousands of compile errors like:
> 
> ```auto
> cl : Command line warning D9025 : overriding '/MDd' with '/MD' 
> 
> ```
> 
> I cannot find any other likely locations where I should insert the compiler flags definitions to get past these compile errors.

This is because these projects are CMP0091-aware and do not expect the runtime to be set manually outside of the property.

---

<div class="post-metadata">

### Author: ![Stan\_Hammon](https://discourse.kitware.com/user_avatar/discourse.kitware.com/stan_hammon/32/487_2.png) [@Stan\_Hammon](https://discourse.kitware.com/u/Stan_Hammon)
#### Post date: [February 16, 2022, 5:56pm UTC](https://discourse.kitware.com/t/building-debug-on-window/770/4 "2022-02-16T17:56:38Z")

</div>

Given the advice above (and recent progress with building `libarchive` in `Debug`), I’ve shifted back to trying to build all needed parts of `cmb-superbuild` in `Debug` rather than pursuing a hybrid approach.

To that end, I need to be able to build the following parts of `cmb-superbuild` in order to move on to building `smtk` (for further use building `cmb`):

- boost
- libarchive
- moab
- nlohmannjson
- paraview
- pegtl
- pybind11

I’m trying to build the smaller modules before moving on to `paraview`. So far, they all build in `Debug` except for `moab`.

The `moab` build fails within `netcdf` due to an error in `hdf5`. Here is the specific error from `netcdf-build-err.log`:

```auto
ninja: error: 'C:/projects/cmb-BenMR/5_15_2_VS19_64D/install/lib/hdf5.lib', needed by 'liblib/netcdf.dll', missing and no known rule to make it
CMake Error at C:/projects/cmb-BenMR/5_15_2_VS19_64D/superbuild/sb-netcdf-build.cmake:47 (message):
  Failed with exit code 1

```

There is a `hdf5_D.lib` present in the build directory, but no `hdf5.lib`.

Do you have any advice or suggestions in regard to this error?
