# Error with CLING when loading library compiled in debug mode on windows10

**URL:** <https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135>\
**Category:** Newbie\
**Created:** [August 24, 2023, 4:12pm UTC](https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135 "2023-08-24T16:12:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricAnciant](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/cc9497/32.png) [@EricAnciant](https://root-forum.cern.ch/u/EricAnciant)\
**Post date:** [August 24, 2023, 4:12pm UTC](https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135/1 "2023-08-24T16:12:16Z")

</div>

Hello Rooters,

I am facing the following problem :

I am trying to load a windows DLL containing a ROOT-CLING dictionary within a root session

When I compile that library with release options this works fine :

## P:\ProgramFiles\ATOS\Win32\bin\Release\>root

| Welcome to ROOT 6.26/10 [https://root.cern](https://root.cern) |  
| (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |  
| Built for win32 on Nov 16 2022, 10:42:54 |  
| From tags/v6-26-10@v6-26-10 |  
| With MSVC 19.29.30151.0 |

| Try ‘.help’, ‘.demo’, ‘.license’, ‘.credits’, ‘.quit’/‘.q’ |
| --- |

root [0] .L libBase.dll  
root [1]

But when I tried to load the same library compiled with debug options  
I get the following errors :

## P:\ProgramFiles\ATOS\Win32\bin\Debug\>root

| Welcome to ROOT 6.26/10 [https://root.cern](https://root.cern) |  
| (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |  
| Built for win32 on Nov 16 2022, 10:42:54 |  
| From tags/v6-26-10@v6-26-10 |  
| With MSVC 19.29.30151.0 |

| Try ‘.help’, ‘.demo’, ‘.license’, ‘.credits’, ‘.quit’/‘.q’ |
| --- |

root [0] .L libBase.dll  
input\_line\_8:1:1: error: source file is not valid UTF-8  
  
^  
input\_line\_8:1:2: error: source file is not valid UTF-8  
  
^  
input\_line\_8:1:3: error: source file is not valid UTF-8  
  
^  
Assertion failed: cling::Interpreter::kSuccess == compRes && “A fwd declaration could not be compiled”, file C:\Users\FRSP812\Desktop\ROOT\root-6.26.10\core\metacling\src\TCling.cxx, line 2077

* * *

and root session crashes

I would appreciate some hints of where to look,  
thanks

eric

\_ROOT Version: ROOT 6.26/10  
\_Platform: Windows10  
\_Compiler:MSVC 19.29.30151.0

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 24, 2023, 4:15pm UTC](https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135/2 "2023-08-24T16:15:49Z")

</div>

First, make sure the DLL you load is built with the same flags than the ones used to build ROOT. E.g. you cannot mix Debug and Release binaries on Windows (this is independent of ROOT)

---

<div class="post-metadata">

**Author:** ![EricAnciant](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/cc9497/32.png) [@EricAnciant](https://root-forum.cern.ch/u/EricAnciant)\
**Post date:** [August 24, 2023, 5:14pm UTC](https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135/3 "2023-08-24T17:14:25Z")

</div>

Hello  
Thanks for the reply,  
Do you mean that I must use ROOT compiled with debug options in order to use debug libraries ?  
So far, I did not have this limitation (always using release version of root distribution whenever using release of debug version of my application libraries )

I 'd already made a quick pass on compilation options. (Not always simple to compare visual studio setup with CMAKE )( and I was assuming that the fact that release version was working fine was hinting for a more simple/obvious error)  
but I will sure look more closely on these options & difference between VS release / VS debug and ROOT CMAKE

thanks again

eric

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 24, 2023, 5:20pm UTC](https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135/4 "2023-08-24T17:20:27Z")

</div>

Well, in fact the debug binaries of ROOT are not linked against the debug runtime libraries (a bit like `RelWithDebInfo`), so it should not really matter, but still, the compiler flags might be an issue. Microsoft is quite tricky when mixing binaries. Can you try to build your DLL in `RelWithDebInfo`? Or at least don’t link with the debug runtime libraries, by using the `/MD` flag instead of the `/MDd` one

EDIT: You can check the C++ flags used to build ROOT with `root-config --cflags`. For example:

```auto
C:\Users\bellenot>root-config --cflags
 -nologo -Zc:__cplusplus -std:c++17 -MD -GR -EHsc- -W3 -D_WIN32 -O2 -IC:\Users\bellenot\build\release\include

```

---

<div class="post-metadata">

**Author:** ![EricAnciant](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/cc9497/32.png) [@EricAnciant](https://root-forum.cern.ch/u/EricAnciant)\
**Post date:** [August 25, 2023, 7:13am UTC](https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135/5 "2023-08-25T07:13:17Z")

</div>

Hello when trying to replace /MDd by /MD I got a bunch of link errors:  
1\> Création de la bibliothèque P:\ProgramFiles\ATOS\Win32\lib\Debug\libBase.lib et de l’objet P:\ProgramFiles\ATOS\Win32\lib\Debug\libBase.exp  
1\>CStopWatch.obj : error LNK2001: symbole externe non résolu \_\_imp\_\_\_invalid\_parameter  
1\>CStream.obj : error LNK2001: symbole externe non résolu \_\_imp\_\_\_invalid\_parameter  
1\>CInStreamer.obj : error LNK2001: symbole externe non résolu \_\_imp\_\_\_invalid\_parameter  
1\>COutStream.obj : error LNK2001: symbole externe non résolu \_\_imp\_\_\_invalid\_parameter  
… and so on …

BTW : the curent compilation flags for that library is :

/ifcOutput “Win32\Debug" /GS /analyze- /W3 /wd"4661” /wd"4251" /wd"4275" /wd"4996" /Zc:wchar\_t /I"P:/ROOT/win32/ROOT\_6.26.10/include" /I"…/include" /Zi /Gm- /Od /Fd"Win32\Debug\vc142.pdb" /Zc:inline /fp:precise /D “WIN32” /D “\_DEBUG” /D “\_WINDOWS” /D “\_USRDLL” /D “LIBBASE\_EXPORTS” /D “\_WINDLL” /D “\_MBCS” /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /Oy- /MDd /std:c++17 /FC /Fa"Win32\Debug" /EHa /nologo /Fo"Win32\Debug" /Fp".\Debug/libBase.pch" /diagnostics:column

(with /MDd option being put back)

I will explore these options this morning (vs Release and/or ROOT)  
(thanks for the root-config --cflags trick BTW …)

eric

---

<div class="post-metadata">

**Author:** ![EricAnciant](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/cc9497/32.png) [@EricAnciant](https://root-forum.cern.ch/u/EricAnciant)\
**Post date:** [August 25, 2023, 7:16am UTC](https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135/6 "2023-08-25T07:16:43Z")

</div>

BTW

I tried to build a toy executable within visual studio that link against that library,  
in release : no problem,  
in debug : I got an exception (see attached image), in case it can give a clue

 ![libBaseDebugExceptionError](https://root-forum.cern.ch/uploads/default/original/3X/d/6/d6f441d15a96b99ee6d74a3871cbedb65117abba.jpeg)

---

<div class="post-metadata">

**Author:** ![EricAnciant](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/cc9497/32.png) [@EricAnciant](https://root-forum.cern.ch/u/EricAnciant)\
**Post date:** [August 25, 2023, 8:58am UTC](https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135/7 "2023-08-25T08:58:40Z")

</div>

I managed to compile with /MD option (I also had to modify Preprocessor flag from \_DEBUG to NDEBUG in order to be abble to link properly )  
and this solved my issue (both interactive use in root session is OK, and there is no more exception when using my toy application)

thanks

Now: what really puzzles me is that within visual studio, I can still debug the library compiled this way : breakpoints and variable content visualisation are still working… which is perfect for my use but confuses me since I was thinking that all the point of this compilation options where to be abble to do this …

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 25, 2023, 9:21am UTC](https://root-forum.cern.ch/t/error-with-cling-when-loading-library-compiled-in-debug-mode-on-windows10/56135/8 "2023-08-25T09:21:53Z")

</div>

Well, FYI, selecting the `RelWithDebInfo` build type would do the same. The difference between `/MD` and `/MDd` is only the runtime libraries type
