'gSystem->Load()' cause 'cout<<anything<<endl;' crash root comand line on Win10


ROOT Version: 6.16.0 and 6.22
Platform: win 10
Compiler: Cling


Hello,

I am troubled by a strange behavior. Root comand line will crash for “cout<<anything<<endl;” if I use
‘gSystem->Load()’ to load a dll or lib file.

I also find that I can’t use ‘gSystem->Load()’ to load ‘.lib’ file in command line, but I can use it in rootlogon.C file successfully.

Any suggestions will be great!

I can’t reproduce the issue you describe:

C:\Users\bellenot\rootdev>root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.23/01                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for win32 on Aug 24 2020, 08:34:25                         |
  | From heads/master@v6-23-01-1046-g8665644005                      |
  | With                                                             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] gSystem->Load("libMathMore.dll")
(int) 0
root [1] std::cout << "hello" << std::endl;
hello
root [2]

IIRC, gSystem->Load() is meant to load DLLs. BTW, did you start ROOT in a x86 Native Tools Command Prompt for VS 2019?

I just find out that I can use gSystem->Load(pathtoLibFile) in command line if I start ROOT in a x86 Native Tools Command Prompt for VS 2019. But, still, if I use std::cout << "hello" << std::endl;, it will print “hello” then quit root. And std::cout <<int, double .etc. << std::endl; will crash command line.

Maybe I use the word ‘crash’ wrongly. By ‘crash’ I mean std::cout << anynumber << std::endl; will print an empty line and then quit root.

Yes, please start ROOT from there, so it can find the proper system header files.
And for the std::endl issue, I still can’t reproduce the issue:

C:\Users\bellenot\rootdev>root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.23/01                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for win32 on Aug 24 2020, 08:34:25                         |
  | From heads/master@v6-23-01-1046-g8665644005                      |
  | With                                                             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] std::cout << 0.04 << std::endl;
0.04
root [1] gSystem->Load("libMathMore.dll")
(int) 0
root [2] std::cout << 0.04876 << " " << 12345 << std::endl;
0.04876 12345
root [3]

But you can most probably use << '\n'; (or << "\n";) instead

I’m sorry, but I find the version I use is 6.22/02, not 6.23. It’s a precompiled version. I thought I tried 6.23. I tried some versions and I make it wrong. I guess I didn’t try 6.23.

OK, anyway, you can try to use << '\n'; (or << "\n"; ) instead of << std::endl;

'\n';` (or `<< "\n";` ) is the same as std::endl;.

OK, I’ll try to reproduce the error…

BTW, which version of Visual Studio are you using?

It’s

Version 16.7.2
Windows 10 SDK (10.0.18362.0)

So no luck, it works for me with the same setup:

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.7.2
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

C:\Users\sftnight>Downloads\root\bin\thisroot.bat

C:\Users\sftnight>root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.22/02                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for win32 on Aug 17 2020, 12:46:52                         |
  | From tags/v6-22-02@v6-22-02                                      |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] gSystem->Load("libGpad.dll")
(int) 0
root [1] std::cout << "kjh " << 12.345 << " " << 12345 << std::endl;
kjh 12.345 12345
root [2]

Could you please help me try this two files? I put it here:

https://1drv.ms/u/s!Ahthsev5X2HBhM463m_WB6DV8qenoA?e=j3WooS

If it works, I’ll begin to compile root on windows.~_~

No, it cannot load the dll… Where is this coming from? How was it build?

It’s from here:


I just use visual studio 2010 open it and press ‘F7’, it’s build for win32.

I also try gSystem->Load("libGpad.dll"). It still causes the problem.

Wait!!! I forgot to delete my rootlogon.C. gSystem->Load(“libGpad.dll”) won’t cause the problem!!! So the dll file itself cause the problem!

It might be due to different versions of Visual Studio, or unsatisfied dependencies of the SeaBreeze.dll. One cannot mix different versions of C++

1 Like

Thank you very much for your help!

Today I reach the maximum number of reply, so I add the update here: I recompile the dll file in VS2019 with option ‘-nostdlib’, and then everything works perfect!

1 Like

You’re very welcome!