a couple of years ago I programmed powerfull classes in a unix enviroment, I had a running build system which directly generated all necessarry libraries to be able to directly use these classes in root.
Nowerdays I’m limited to a Windows system and I would like to recover some of these old classes, because of this I’m asking:
“Is there a documentation somewhere describing what steps need to be done to build classes in Visual Studio in order to make these classes available in the root environment?”
I know about all the #pragma stuff, but what I’m search for is a minimal Visual Studio project containing an example class.
Alternatively: Some minimal code and the necessary build commands and the commands to generate the dictionaries
Thanks
Georg
ROOT Version: 6.28.06 Platform: Windows Compiler: Visual Studio 2022 (17.3.3)
Well, you can use the same procedure than on Linux, with CMake. I you have a concrete use case I can help you fixing the issue you might have on Windows.
Thank you for your help. Let me try it a bit more specific:
I created a simple test class inside a DLL-template of visual studio:
#pragma once
class gttest
{
public:
gttest() {}
virtual ~gttest() {}
int run() { return 42; }
};
#ifdef __CLING__
#pragma link C++ class gttest+;
#endif // __CLING__
it compiles and creates a dll-file.
Then manually I ran:
rootcling-exe -f DictOutput.cxx gttest.h
which again creates me DictOutput.cxx and DictOutput_rdict.pcm (I’m sure I can add this to the Dll-template, so it runs automatically)
In my old unix environment I had to do some path-magic after that (adding to LD_LIBRARY_PATH) to let root know where to find something.
Here I tried to copy everything into one folder, as I do not know how to handle the path magic in windows, unfortunately root still doesn’t know anything about “gttest”.
PS C:\Users\troska\source\repos\root20260116\x64\Debug> .\dumpbin.exe /exports .\root20260116.dll
Microsoft (R) COFF/PE Dumper Version 14.44.35222.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file .\root20260116.dll
File Type: DLL
Summary
1000 .00cfg
1000 .data
1000 .idata
1000 .msvcjmc
3000 .pdata
3000 .rdata
1000 .reloc
1000 .rsrc
8000 .text
10000 .textbss
PS C:\Users\troska\source\repos\root20260116\x64\Debug>
nothing inside….I hate Visual Studio so much (thinks are som much more transparent with Makefiles)… what is necessary to export all symbols inside this Dll-project?
#pragma once
class __declspec(dllexport) gttest
{
public:
gttest() {}
virtual ~gttest() {}
int run() { return 42; }
};
#ifdef __CLING__
#pragma link C++ class gttest+;
#endif // __CLING__
due to this there is something inside now:
PS C:\Users\troska\source\repos\root20260116\x64\Debug> .\dumpbin.exe /exports .\root20260116.dll
Microsoft (R) COFF/PE Dumper Version 14.44.35222.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file .\root20260116.dll
File Type: DLL
Section contains the following exports for root20260116.dll
00000000 characteristics
FFFFFFFF time date stamp
0.00 version
1 ordinal base
6 number of functions
6 number of names
ordinal hint RVA name
1 0 0001134D ??0gttest@@QEAA@AEBV0@@Z = @ILT+840(??0gttest@@QEAA@AEBV0@@Z)
2 1 000112EE ??0gttest@@QEAA@XZ = @ILT+745(??0gttest@@QEAA@XZ)
3 2 000111C7 ??1gttest@@UEAA@XZ = @ILT+450(??1gttest@@UEAA@XZ)
4 3 00011104 ??4gttest@@QEAAAEAV0@AEBV0@@Z = @ILT+255(??4gttest@@QEAAAEAV0@AEBV0@@Z)
5 4 0001A888 ??_7gttest@@6B@ = ??_7gttest@@6B@ (const gttest::`vftable')
6 5 000111B8 ?run@gttest@@QEAAHXZ = @ILT+435(?run@gttest@@QEAAHXZ)
Summary
1000 .00cfg
1000 .data
1000 .idata
1000 .msvcjmc
3000 .pdata
3000 .rdata
1000 .reloc
1000 .rsrc
9000 .text
10000 .textbss
PS C:\Users\troska\source\repos\root20260116\x64\Debug>
great!
I reran rootcling.exe
but unfortunately:
root [0] gSystem->Load(“root20260116”) (int) 0 root [1] gttest input_line_11:2:3: error: use of undeclared identifier ‘gttest’ (gttest) ^ root [2]
So here is my proposed solution, using CMake, with the attached CMakeLists.txt. Add it in your C:\Users\troska\source\repos\root20260116 directory, and create a build subdirectory.
Then open a Developer Command Prompt for VS 2022 and go to C:\Users\troska\source\repos\root20260116\build. Then, assuming ROOTSYS is properly set, type:
cmake -Wno-dev -G"Visual Studio 17 2022" -A x64 -Thost=x64 -DCMAKE_VERBOSE_MAKEFILE=ON ..\
The output should look like:
C:\Users\troska\source\repos\root20260116\build>cmake -Wno-dev -G"Visual Studio 17 2022" -A x64 -Thost=x64 -DCMAKE_VERBOSE_MAKEFILE=ON ..\
-- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.26200.
-- The CXX compiler identification is MSVC 19.44.35222.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.7s)
-- Generating done (0.0s)
-- Build files have been written to: C:\Users\troska\source\repos\root20260116\build
At the end, if the build is successful, try again dumpbin /exports Release\root20260116.dll, to see the difference…
And finally, you can try with ROOT:
PS C:\Users\troska\source\repos\root20260116\root20260116\build\Release> cmake -Wno-dev -G"Visual Studio 17 2022" -A x64 -Thost=x64 -DCMAKE_VERBOSE_MAKEFILE=ON ..\ -- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22631. CMake Error at CMakeLists.txt:20 (ROOT_SET_OUTPUT_DIRECTORIES): Unknown CMake command "ROOT_SET_OUTPUT_DIRECTORIES".
-- Configuring incomplete, errors occurred!
I removed it and had to move the pcm and rootmapfiles manually to the Relase-folder.
Anyhow this brings me forward enourmously - thank you
Are you always typing the cmake-stuff in the terminal or have you connected the visual studio build command to the cmake-file somehow? I do not know if there is a straight forward way of doing this
I have never used cmake, I always preferred autogen.sh && ./configure && make
Right, sorry, I forgot to remove that line, which is only working with the current head
You’re very welcome! And yes, I’m used to use the command prompt, especially because I’m very often connecting to VMs via ssh. I general I only use Visual Studio for debugging purposes.
although the original post is answered, I still need some help with your CMakeLists.txt.
I’m not very familiar with CMakeList - so sorry for asking so stupid questions
My original code is much more than one header file. How can I add the *.cpp files and tell Cmake to create the objects before linking? By know I’m getting Linker errors, as there are unresolved external symbols
C:\Users\troska\Desktop\git\measure\build>cmake -Wno-dev -G"Visual Studio 17 2022" -A x64 -Thost=x64 -DCMAKE_VERBOSE_MAKEFILE=ON ..\src\
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22631.
CMake Error at CMakeLists.txt:54 (add_library):
add_library cannot create target "measure" because another target with the
same name already exists. The existing target is a shared library created
in source directory "C:/Users/troska/Desktop/git/measure/src". See
documentation for policy CMP0002 for more details.
-- Configuring incomplete, errors occurred!
If you read carefully the error message, you can see: add_library cannot create target "measure" because another target with the same name already exists.
Try: