When I tried replacing ‘root-config --cflags --glibs’ with its output, it gave me these errors:
g++: error: /link: No such file or directory
g++: error: libCore.lib: No such file or directory
g++: error: libImt.lib: No such file or directory
g++: error: libRIO.lib: No such file or directory
g++: error: libNet.lib: No such file or directory
g++: error: libHist.lib: No such file or directory
g++: error: libGraf.lib: No such file or directory
g++: error: libGraf3d.lib: No such file or directory
g++: error: libGpad.lib: No such file or directory
g++: error: libROOTVecOps.lib: No such file or directory
g++: error: libTree.lib: No such file or directory
g++: error: libTreePlayer.lib: No such file or directory
g++: error: libRint.lib: No such file or directory
g++: error: libPostscript.lib: No such file or directory
g++: error: libMatrix.lib: No such file or directory
g++: error: libPhysics.lib: No such file or directory
g++: error: libMathCore.lib: No such file or directory
g++: error: libThread.lib: No such file or directory
g++: error: libGui.lib: No such file or directory
g++: error: unrecognized command-line option '-nologo'
g++: error: unrecognized command-line option '-Zc:__cplusplus'
g++: error: unrecognized command-line option '-std:c++17'; did you mean '-std=c++17'?
g++: error: unrecognized command-line option '-GR'; did you mean '-R'?
g++: error: unrecognized command-line option '-EHsc-'
g++: error: unrecognized command-line option '-W3'; did you mean '-W'?
I use Windows 10. My root version is 6.26/10. The compiler is g++.
Use CMake or cl.exe on the command prompt. And note that on Windows, you cannot use the return string given by root-config --cflags --glibs as on Linux. But you can copy and paste it in the Native Tools Command Prompt for VS 2022 (or 2019) itself. E.g.:
You’re mixing cmake, used to generate makefiles or project/solution files and flags used by the compiler (here cl.exe).
I think the simplest way for you is to use CMake to generate your DLL. To do so, use for example this simple CMakeLists.txt:
# Check if cmake has the required version
CMAKE_MINIMUM_REQUIRED(VERSION 3.16.4 FATAL_ERROR)
project(mydict)
find_package(ROOT REQUIRED)
set(CMAKE_CXX_FLAGS "${ROOT_CXX_FLAGS}")
include(${ROOT_USE_FILE})
include_directories(${ROOT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
link_directories(${ROOT_LIBRARY_DIR})
add_library(libmydict SHARED mydict.cxx)
target_link_libraries(libmydict ${ROOT_LIBRARIES})
set_target_properties(libmydict PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
place it in the same directory than your source file (mydict.cxx) then use it as any CMakeLists.txt file to generate and build your DLL from a build directory. Note that you must execute this from a x86 Native Tools Command Prompt for VS 2022 (for 32 bit) or a x64 Native Tools Command Prompt for VS 2022 (for 64bit) from the directory of your source code:
mkdir build
cd build
cmake -G"Visual Studio 17 2022" -A Win32 -Thost=x64 ..\
cmake --build . --config Release
and adapt this line:
cmake -G"Visual Studio 17 2022" -A Win32 -Thost=x64 ..\
with the version of Visual Studio you have and the architecture you want (-A Win32 or -A x64), which must be the same than the one ROOT was built for