Command Line Options Not Working

I tried to run this command:

g++ -shared -o libmydict.so mydict.cxx 'root-config --cflags --glibs' -fPIC

I got these errors when I did:

g++: error: 'root-config: No such file or directory
g++: error: unrecognized command-line option '--cflags'
g++: error: unrecognized command-line option '--glibs''

When I ran the root-config part of it by itself, I get this:

 -nologo -Zc:__cplusplus -std:c++17 -MD -GR -EHsc- -W3 -D_WIN32 -O2 -I\include /link -LIBPATH:\lib libCore.lib libImt.lib libRIO.lib libNet.lib libHist.lib libGraf.lib libGraf3d.lib libGpad.lib libROOTVecOps.lib libTree.lib libTreePlayer.lib libRint.lib libPostscript.lib libMatrix.lib libPhysics.lib libMathCore.lib libThread.lib libGui.lib

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++.

` != ' so:

`root-config --cflags --glibs`

or:

$(root-config --cflags --glibs)

When I tried to run this:

g++ -shared -o libmydict.so mydict.cxx `root-config --cflags --glibs` -fPIC

It gave me these errors:

g++: error: `root-config: No such file or directory
g++: error: unrecognized command-line option '--cflags'
g++: error: unrecognized command-line option '--glibs`'

Replacing ’ with ` does not appear to work.

It seems that ROOT 6.26/10 on Windows uses “Visual Studio”, not GCC (and you are probably not using any Unix shell to execute commands).

I am using the command prompt, which I am almost certain is not a Unix shell.

@bellenot How do I compile it with Visual Studio?

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.:

C:\Users\bellenot>root-config --cflags --glibs
 -nologo -Zc:__cplusplus -std:c++17 -MD -GR -EHsc- -W3 -D_WIN32 -O2 -IC:\Users\bellenot\build\x86\release\include /link -LIBPATH:C:\Users\bellenot\build\x86\release\lib libCore.lib libImt.lib libRIO.lib libNet.lib libHist.lib libGraf.lib libGraf3d.lib libGpad.lib libROOTVecOps.lib libTree.lib libTreePlayer.lib libRint.lib libPostscript.lib libMatrix.lib libPhysics.lib libMathCore.lib libThread.lib libGui.lib

But if you want to create a DLL, I would suggest to use CMake, since one need to tell the linker what symbols to export from the DLL

I tried to run this:

cmake -nologo -Zc:__cplusplus -std:c++17 -MD -GR -EHsc- -W3 -D_WIN32 -O2 -I\include /link -LIBPATH:\lib libCore.lib libImt.lib libRIO.lib libNet.lib libHist.lib libGraf.lib libGraf3d.lib libGpad.lib libROOTVecOps.lib libTree.lib libTreePlayer.lib libRint.lib libPostscript.lib libMatrix.lib libPhysics.lib libMathCore.lib libThread.lib libGui.lib libmydict.so mydict.cxx

and I got this error:

CMake Error: Could not create named generator R

Generators
  Visual Studio 17 2022        = Generates Visual Studio 2022 project files.
                                 Use -A option to specify architecture.
* Visual Studio 16 2019        = Generates Visual Studio 2019 project files.
                                 Use -A option to specify architecture.
  Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 11 2012 [arch] = Deprecated.  Generates Visual Studio 2012
                                 project files.  Optional [arch] can be
                                 "Win64" or "ARM".
  Visual Studio 9 2008 [arch]  = Generates Visual Studio 2008 project files.
                                 Optional [arch] can be "Win64" or "IA64".
  Borland Makefiles            = Generates Borland makefiles.
  NMake Makefiles              = Generates NMake makefiles.
  NMake Makefiles JOM          = Generates JOM makefiles.
  MSYS Makefiles               = Generates MSYS makefiles.
  MinGW Makefiles              = Generates a make file for use with
                                 mingw32-make.
  Green Hills MULTI            = Generates Green Hills MULTI files
                                 (experimental, work-in-progress).
  Unix Makefiles               = Generates standard UNIX makefiles.
  Ninja                        = Generates build.ninja files.
  Ninja Multi-Config           = Generates build-<Config>.ninja files.
  Watcom WMake                 = Generates Watcom WMake makefiles.
  CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
  CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
  CodeBlocks - NMake Makefiles JOM
                               = Generates CodeBlocks project files.
  CodeBlocks - Ninja           = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
  CodeLite - MinGW Makefiles   = Generates CodeLite project files.
  CodeLite - NMake Makefiles   = Generates CodeLite project files.
  CodeLite - Ninja             = Generates CodeLite project files.
  CodeLite - Unix Makefiles    = Generates CodeLite project files.
  Eclipse CDT4 - NMake Makefiles
                               = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - MinGW Makefiles
                               = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
  Kate - MinGW Makefiles       = Generates Kate project files.
  Kate - NMake Makefiles       = Generates Kate project files.
  Kate - Ninja                 = Generates Kate project files.
  Kate - Unix Makefiles        = Generates Kate project files.
  Sublime Text 2 - MinGW Makefiles
                               = Generates Sublime Text 2 project files.
  Sublime Text 2 - NMake Makefiles
                               = Generates Sublime Text 2 project files.
  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                               = Generates Sublime Text 2 project files.

CMake Warning:
  Ignoring extra path from command line:

   "mydict.cxx"


CMake Error: Unknown argument -LIBPATH:\lib
CMake Error: Run 'cmake --help' for all supported options.

It doesn’t recognize the -LIBPATH:\lib argument returned by root-config and ignores one of the files.

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

Would it work if I ran it from x64 Native Tools Command Prompt for VS 2019? If not, how do I install the Native Tools Command Prompt for VS 2022?

Yes, if you downloaded the x64 version of ROOT