Linking ROOT libs with cmake on windows

I use ROOT 5.34 windows distribution ( and would like to compile my own program which use Geant4 and root libs. I add to my CMakeLists.txt lines

find_package(ROOT REQUIRED)


target_link_libraries(exampleN06 ${Geant4_LIBRARIES} ${ROOT_LIBRARIES})

Using this all Geant4 staff are founded and added, but ROOT libs are missing. cmake didnt find any ROOT libs and explicitly ask me only about cint and core lib. I dig over ROOTConfig.cmake file and found

foreach(cpt Core Cint ${ROOT_FIND_COMPONENTS})

seems that ROOT_FIND_COMPONENTS var are not filled properly on windows. So I use “dirty hack” and add

set(ROOT_FIND_COMPONENTS Cint Reflex genmap Cintex Rint Thread rootcint rlibmap Core rmkdepend bindexplib MathCore MathMore Matrix Minuit Minuit2 Fumili Physics MLP Quadp Foam Smatrix SPlot GenVector Genetic Unuran Hist HistPainter Spectrum SpectrumPainter Tree TreePlayer TreeViewer RIO SQLIO XMLIO Net RootAuth RHTTP Gpad Graf Postscript mathtext Win32gdk ASImage ASImageGui Graf3d Eve RGL GLEW FTGL Gviz3d Gui Ged FitPanel GuiBld GuiHtml Recorder SessionViewer Proof ProofPlayer ProofDraw Html EG VMC EGPythia8 Geom GeomBuilder GeomPainter Gdml Table root.exe proofserv.exe hadd PyROOT RODBC TMVA RooFitCore RooFit RooStats)

to ROOTConfig.cmake just before set(ROOT_LIBRARIES). Now cmake began to ask me about all ROOT libs and still not finding them himself. So I make a copy of all ROOT libs with windows name style, like
libCore.lib -> Core.lib

and now cmake find all nessesary staff himself and my program compiles and run. My questions is how to do this in more “elegant” way, without modifying and renaming ROOT files?


Dear Denis,

The idea was that you need to indicate in the find_package(…) the components (libraries) that you require for your application. For the 6 version we have added the ‘standard’ ROOT libraries implicitly but for for 5. This could be done if this is more convenient. So, something like this should work for you.

find_package(ROOT REQUIRED COMPONENTS RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread)

Hi mato,
It works now, but I still need to rename all libs like libCore.lib -> Core.lib in order to cmake find them himself.
B.t.w. why on linux machine also with ROOT 5 only

enough and cmake add all ROOT libs to project?


Dear Denis,

The need for renaming the libraries is certainly a bug. Thanks for reporting it. I would perhaps change the library names when building and use a more Windows friendly name, but we need to evaluate the consequences. Alternatively we can change the find_library() to locate them properly.
We didn’t change to implicitly add all the ‘normal’ libraries in ROOT5 because the release is frozen at this point. If we need to make a fix for the library names, I will do also do this.


Fix documented in