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

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 |
| (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 |
| (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


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)

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

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:

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

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

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

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 …

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