ROOT Windows 32 bit Installation

ROOT Version: Release 6.28/06 - 2023-08-28

Platform: Windows
Compiler: CMake


Hello, I have been trying for hours installing ROOT and running it with one of my builds, but it keeps popping this error up (or something like this):

–Looking for Root… - found C:/ROOT/bin/root
–Looking for Root… - version Process failed because: %1 is not a valid Win32 application

It would also do this to others too like for root-config.
I have tried to make sure I have all 32 bit applications setup (for CMake, Visual Studio, QtSource and the ROOT 32 bit version). I am now stuck!

Welcome to the ROOT forum

As it is on windows the best person to help you is @bellenot

I would need more informations. Which exact version of ROOT did you install? Can you attach your CMakeLists.txt?

Hi, I installed root_v6.28.06.win32.vc17.exe
Here is my CMakelists.txt for my build:

#----------------------------------------------------------------------------
# Setup the project
#
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(AS)

#----------------------------------------------------------------------------
# Find Geant4 package, activating all available UI and Vis drivers by default
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
# to build a batch mode only executable
#
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
  find_package(Geant4 REQUIRED ui_all vis_all)
else()
  find_package(Geant4 REQUIRED)
endif()

#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
# Setup include directory for this project
#
include(${Geant4_USE_FILE})
include_directories(${PROJECT_SOURCE_DIR}/include)

#----------------------------------------------------------------------------
#find_package(ROOT)

#I would also change include_directories(/usr/include/root/) to
#include_directories(${ROOT_INCLUDE_DIR})

#Both ROOT_LIBRARIES and ROOT_INCLUDE_DIR are set if the FindROOT macro finds package ROOT.

#ROOT_LIBRARIES only holds a couple of most used root libs, so in case you need to add some specific libs, (e.g. Eve), use:
#set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lEve)



# This allows CMake to find your module
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} ${CMAKE_MODULE_PATH})

# Find ROOT
find_package(ROOT)

# Add ROOTs header paths
include_directories(${ROOT_INCLUDE_DIR})

# Build your executable
#add_executable(MyExe MyExe.cpp)

# Link executable to ROOT libraries



#----------------------------------------------------------------------------
# Locate sources and headers for this project
# NB: headers are included so they will show up in IDEs
#
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)

#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(SimpleDet SimpleDet.cc ${sources} ${headers})
target_link_libraries(SimpleDet ${Geant4_LIBRARIES})
#target_link_libraries(SimpleDet ${ROOT_LIBRARIES})

target_link_libraries(SimpleDet ${ROOT_LIBRARIES})

#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
# build SimpleDet. This is so that we can run the executable directly because it
# relies on these scripts being in the current working directory.
#
set(SimpleDet_SCRIPTS
  vis.mac
  )

foreach(_script ${SimpleDet_SCRIPTS})
  configure_file(
    ${PROJECT_SOURCE_DIR}/${_script}
    ${PROJECT_BINARY_DIR}/${_script}
    COPYONLY
    )
endforeach()

#----------------------------------------------------------------------------
# For internal Geant4 use - but has no effect if you build this
# example standalone
#
add_custom_target(AS DEPENDS SimpleDet)

#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
install(TARGETS SimpleDet DESTINATION bin)



In addition, (this build is actually my supervisor’s build), the build has this “FindRoot.cmake” file that contains this:

# - Find ROOT instalation
# This module tries to find the ROOT installation on your system.
# It tries to find the root-config script which gives you all the needed information.
# If the system variable ROOTSYS is set this is straight forward.
# If not the module uses the pathes given in ROOT_CONFIG_SEARCHPATH.
# If you need an other path you should add this path to this varaible.  
# The root-config script is then used to detect basically everything else.
# This module defines a number of key variables and macros.

# F.Uhlig@gsi.de (fairroot.gsi.de)


MESSAGE(STATUS "Looking for Root...")

SET(ROOT_CONFIG_SEARCHPATH
  ${SIMPATH}/tools/root/bin
  $ENV{ROOTSYS}/bin
)

SET(ROOT_DEFINITIONS "")

SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)

SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)

FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS
   ${ROOT_CONFIG_SEARCHPATH}
   NO_DEFAULT_PATH)
    
IF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
  MESSAGE( FATAL_ERROR "ROOT not installed in the searchpath and ROOTSYS is not set. Please
 set ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the
 subdirectory cmake/modules.")
ELSE (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
  STRING(REGEX REPLACE "(^.*)/bin/root-config" "\\1" test ${ROOT_CONFIG_EXECUTABLE}) 
  SET( ENV{ROOTSYS} ${test})
  set( ROOTSYS ${test})
ENDIF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")  

 
IF (ROOT_CONFIG_EXECUTABLE)
   
  SET(ROOT_FOUND FALSE)

  EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION)

  MESSAGE(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
  MESSAGE(STATUS "Looking for Root... - version ${ROOTVERSION} ")   

  # we need at least version 5.00/00
  IF (NOT ROOT_MIN_VERSION)
    SET(ROOT_MIN_VERSION "5.00/00")
  ENDIF (NOT ROOT_MIN_VERSION)
   
  # now parse the parts of the user given version string into variables
  STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}")
  STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}")
  STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}")
   
  # and now the version string given by qmake
  STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}")
  STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}")
  STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}")

  IF (found_root_major_vers LESS 5)
    MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"")
  ENDIF (found_root_major_vers LESS 5)

  # compute an overall version number which can be compared at once
  MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}")
  MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}")
   
  IF (found_vers LESS req_vers)
    SET(ROOT_FOUND FALSE)
    SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
  ELSE (found_vers LESS req_vers)
    SET(ROOT_FOUND TRUE)
  ENDIF (found_vers LESS req_vers)

ENDIF (ROOT_CONFIG_EXECUTABLE)


IF (ROOT_FOUND)

  # ask root-config for the library dir
  # Set ROOT_LIBRARY_DIR

  EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
    ARGS "--libdir"
    OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )

  IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
    SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} )
  ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
    MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,")
    MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.")
  ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
    
  # ask root-config for the binary dir
  EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE}
    ARGS "--bindir"
    OUTPUT_VARIABLE root_bins )
  SET(ROOT_BINARY_DIR ${root_bins})

  # ask root-config for the include dir
  EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
    ARGS "--incdir" 
    OUTPUT_VARIABLE root_headers )
  SET(ROOT_INCLUDE_DIR ${root_headers})
      # CACHE INTERNAL "")

  # ask root-config for the library varaibles
  EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
#    ARGS "--noldflags --noauxlibs --libs" 
    ARGS "--glibs" 
    OUTPUT_VARIABLE root_flags )

#  STRING(REGEX MATCHALL "([^ ])+"  root_libs_all ${root_flags})
#  STRING(REGEX MATCHALL "-L([^ ])+"  root_library ${root_flags})
#  REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}")

  SET(ROOT_LIBRARIES ${root_flags})

  # Make variables changeble to the advanced user
  MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)

  # Set ROOT_INCLUDES
  SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})

  SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})

  #######################################
  #
  #       Check the executables of ROOT 
  #          ( rootcint ) 
  #
  #######################################

  FIND_PROGRAM(ROOT_CINT_EXECUTABLE
    NAMES rootcint
    PATHS ${ROOT_BINARY_DIR}
    NO_DEFAULT_PATH
    )

ENDIF (ROOT_FOUND)



  ###########################################
  #
  #       Macros for building ROOT dictionary
  #
  ###########################################

MACRO (ROOT_GENERATE_DICTIONARY_OLD )
 
   set(INFILES "")    

   foreach (_current_FILE ${ARGN})

     IF (${_current_FILE} MATCHES "^.*\\.h$")
       IF (${_current_FILE} MATCHES "^.*Link.*$")
         set(LINKDEF_FILE ${_current_FILE})
       ELSE (${_current_FILE} MATCHES "^.*Link.*$")
         set(INFILES ${INFILES} ${_current_FILE})
       ENDIF (${_current_FILE} MATCHES "^.*Link.*$")
     ELSE (${_current_FILE} MATCHES "^.*\\.h$")
       IF (${_current_FILE} MATCHES "^.*\\.cxx$")
         set(OUTFILE ${_current_FILE})
       ELSE (${_current_FILE} MATCHES "^.*\\.cxx$")
         set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})   
       ENDIF (${_current_FILE} MATCHES "^.*\\.cxx$")
     ENDIF (${_current_FILE} MATCHES "^.*\\.h$")
     
   endforeach (_current_FILE ${ARGN})
   
#  MESSAGE("INFILES: ${INFILES}")
#  MESSAGE("OutFILE: ${OUTFILE}")
#  MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
#  MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")

   STRING(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}")
#   MESSAGE("BLA: ${bla}")
   SET (OUTFILES ${OUTFILE} ${bla})

   ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
      COMMAND ${ROOT_CINT_EXECUTABLE}
      ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})

#   MESSAGE("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}")

ENDMACRO (ROOT_GENERATE_DICTIONARY_OLD)

  ###########################################
  #
  #       Macros for building ROOT dictionary
  #
  ###########################################

MACRO (ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
 
  set(INCLUDE_DIRS)

  foreach (_current_FILE ${INCLUDE_DIRS_IN})
    set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})   
  endforeach (_current_FILE ${INCLUDE_DIRS_IN})
 

#  MESSAGE("INFILES: ${INFILES}")
#  MESSAGE("OutFILE: ${OUTFILE}")
#  MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
#  MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")

  STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}")
#  MESSAGE("BLA: ${bla}")
  SET (OUTFILES ${OUTFILE} ${bla})


  if (CMAKE_SYSTEM_NAME MATCHES Linux)
    ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
       COMMAND LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
       ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
  else (CMAKE_SYSTEM_NAME MATCHES Linux)
    if (CMAKE_SYSTEM_NAME MATCHES Darwin)
      ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
       COMMAND DYLD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
       ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
    endif (CMAKE_SYSTEM_NAME MATCHES Darwin)
  endif (CMAKE_SYSTEM_NAME MATCHES Linux)

ENDMACRO (ROOT_GENERATE_DICTIONARY)

MACRO (GENERATE_ROOT_TEST_SCRIPT SCRIPT_FULL_NAME)

  get_filename_component(path_name ${SCRIPT_FULL_NAME} PATH)
  get_filename_component(file_extension ${SCRIPT_FULL_NAME} EXT)
  get_filename_component(file_name ${SCRIPT_FULL_NAME} NAME_WE)
  set(shell_script_name "${file_name}.sh")

  #MESSAGE("PATH: ${path_name}")
  #MESSAGE("Ext: ${file_extension}")
  #MESSAGE("Name: ${file_name}")
  #MESSAGE("Shell Name: ${shell_script_name}")

  string(REPLACE ${PROJECT_SOURCE_DIR} 
         ${PROJECT_BINARY_DIR} new_path ${path_name}
        )

  #MESSAGE("New PATH: ${new_path}")

  file(MAKE_DIRECTORY ${new_path}/data)

  CONVERT_LIST_TO_STRING(${LD_LIBRARY_PATH})
  set(MY_LD_LIBRARY_PATH ${output})
  set(my_script_name ${SCRIPT_FULL_NAME})

  if(CMAKE_SYSTEM MATCHES Darwin)
    configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro_macos.sh.in
                   ${new_path}/${shell_script_name}
                  )
  else(CMAKE_SYSTEM MATCHES Darwin)
    configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro.sh.in
                   ${new_path}/${shell_script_name}
                  )
  endif(CMAKE_SYSTEM MATCHES Darwin)

  EXEC_PROGRAM(/bin/chmod ARGS "u+x  ${new_path}/${shell_script_name}")

ENDMACRO (GENERATE_ROOT_TEST_SCRIPT)

OK, thanks. So that’s the issue. This is for MacOS and Linux only, and will not work on Windows.

Is there a way to make this work for Windows from his build? or maybe does ROOT not do that? (I am new to ROOT btw!)

Well, this is not part of ROOT, and I would need some time to see if that can be adapted for Windows. I will first try to figure out if this is needed at all, but this will also take a bit of time…

Okay thank you! I am trying to multitask and focus on another task at the same time so please let me know when you figure it out :slight_smile:

BTW, can you try to build your application without using this FindRoot.cmake, simply by calling C:\ROOT\bin\root\bin\thisroot.bat before configuring your project?

This is what happened:

C:\SimpleDet\build>%THISROOTBAT%

C:\SimpleDet\build>cmake ..
-- Building for: Visual Studio 17 2022
CMake Deprecation Warning at CMakeLists.txt:4 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.37.32825.0
-- The CXX compiler identification is MSVC 19.37.32825.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- 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.37.32822/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Found OpenGL: opengl32
-- Found Geant4: C:/Users/lmaoi/GEANT4/11.1.2/lib/cmake/Geant4/Geant4Config.cmake (found version "11.1.2")
-- Configuring done (5.6s)
-- Generating done (0.1s)
-- Build files have been written to: C:/SimpleDet/build

C:\SimpleDet\build>cmake --build . --config release
MSBuild version 17.7.2+d6990bcfa for .NET Framework

  1>Checking Build System
  Building Custom Rule C:/SimpleDet/CMakeLists.txt
  SimpleDet.cc
C:\SimpleDet\include\SimpleDetEventAction.hh(42,10): fatal  error C1083: Cannot open include file: 'TTree.h': No such f
ile or directory [C:\SimpleDet\build\SimpleDet.vcxproj]
  SimpleDetActionInitialization.cc
C:\SimpleDet\include\SimpleDetEventAction.hh(42,10): fatal  error C1083: Cannot open include file: 'TTree.h': No such f
ile or directory [C:\SimpleDet\build\SimpleDet.vcxproj]
  SimpleDetDetectorConstruction.cc
C:\SimpleDet\include\SimpleDetEventAction.hh(42,10): fatal  error C1083: Cannot open include file: 'TTree.h': No such f
ile or directory [C:\SimpleDet\build\SimpleDet.vcxproj]
  SimpleDetDetectorMessenger.cc
C:\SimpleDet\include\SimpleDetEventAction.hh(42,10): fatal  error C1083: Cannot open include file: 'TTree.h': No such f
ile or directory [C:\SimpleDet\build\SimpleDet.vcxproj]
  SimpleDetEventAction.cc
C:\SimpleDet\include\SimpleDetRunAction.hh(43,10): fatal  error C1083: Cannot open include file: 'TFile.h': No such fil
e or directory [C:\SimpleDet\build\SimpleDet.vcxproj]
  SimpleDetHit.cc
C:\SimpleDet\src\SimpleDetHit.cc(40,10): fatal  error C1083: Cannot open include file: 'TROOT.h': No such file or direc
tory [C:\SimpleDet\build\SimpleDet.vcxproj]
  SimpleDetMagneticField.cc
  SimpleDetPhysicsList.cc
  SimpleDetPrimaryGeneratorAction.cc
C:\SimpleDet\src\SimpleDetPrimaryGeneratorAction.cc(42,10): fatal  error C1083: Cannot open include file: 'TRandom.h':
No such file or directory [C:\SimpleDet\build\SimpleDet.vcxproj]
  SimpleDetRunAction.cc
C:\SimpleDet\include\SimpleDetEventAction.hh(42,10): fatal  error C1083: Cannot open include file: 'TTree.h': No such f
ile or directory [C:\SimpleDet\build\SimpleDet.vcxproj]
  SimpleDetSD.cc
C:\SimpleDet\src\SimpleDetSD.cc(100,15): warning C4267: 'initializing': conversion from 'size_t' to 'G4int', possible l
oss of data [C:\SimpleDet\build\SimpleDet.vcxproj]
  SimpleDetSteppingAction.cc
  SimpleDetSteppingVerbose.cc
C:\SimpleDet\src\SimpleDetSteppingVerbose.cc(54,14): warning C4244: 'initializing': conversion from 'std::streamsize' t
o 'G4int', possible loss of data [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\SimpleDet\src\SimpleDetSteppingVerbose.cc(127,12): warning C4244: 'initializing': conversion from 'std::streamsize'
to 'G4int', possible loss of data [C:\SimpleDet\build\SimpleDet.vcxproj]
  Generating Code...

Are you sure that %THISROOTBAT% properly calls C:\ROOT\bin\root\bin\thisroot.bat (or wherever ROOT is installed)?
And you need (at least) the following lines in your CMakeLists.txt:

find_package(ROOT REQUIRED)
set(CMAKE_CXX_FLAGS "${ROOT_CXX_FLAGS}")
include(${ROOT_USE_FILE})
include_directories(${ROOT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})
link_directories(${ROOT_LIBRARY_DIR})

Yes, that would call the thisroot.bat.
In my CMakeLists.txt (not the FindCMake thingy), it contains this:

#----------------------------------------------------------------------------
#find_package(ROOT)

#I would also change include_directories(/usr/include/root/) to
#include_directories(${ROOT_INCLUDE_DIR})

#Both ROOT_LIBRARIES and ROOT_INCLUDE_DIR are set if the FindROOT macro finds package ROOT.

#ROOT_LIBRARIES only holds a couple of most used root libs, so in case you need to add some specific libs, (e.g. Eve), use:
#set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lEve)



# This allows CMake to find your module
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} ${CMAKE_MODULE_PATH})

# Find ROOT
find_package(ROOT)

# Add ROOTs header paths
include_directories(${ROOT_INCLUDE_DIR})

# Build your executable
#add_executable(MyExe MyExe.cpp)

# Link executable to ROOT libraries

Would I have to edit it and if so, how would I properly do that?

What do you mean? You don’t know how to edit a file?

No i do, I am wondering what I would edit in the file or would I just simply add it into my file.

OK, so replace these lines:

# Find ROOT
find_package(ROOT)

# Add ROOTs header paths
include_directories(${ROOT_INCLUDE_DIR})

By

# Find ROOT
find_package(ROOT REQUIRED)

include(${ROOT_USE_FILE})
set(CMAKE_CXX_FLAGS "${ROOT_CXX_FLAGS}")

# Add ROOTs header paths
include_directories(${ROOT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})

# Add ROOTs librarr\y paths
link_directories(${ROOT_LIBRARY_DIR})

This is what the errors popped up:

SimpleDetEventAction.obj : error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionCheck(int)
" (??0TVersionCheck@@QEAA@H@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDetHit.obj : error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionCheck(int)" (??0TV
ersionCheck@@QEAA@H@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDetPrimaryGeneratorAction.obj : error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersio
nCheck(int)" (??0TVersionCheck@@QEAA@H@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDetRunAction.obj : error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionCheck(int)"
(??0TVersionCheck@@QEAA@H@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDet.obj : error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionCheck(int)" (??0TVers
ionCheck@@QEAA@H@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDetActionInitialization.obj : error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionC
heck(int)" (??0TVersionCheck@@QEAA@H@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDetDetectorConstruction.obj : error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionC
heck(int)" (??0TVersionCheck@@QEAA@H@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDetDetectorMessenger.obj : error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionChec
k(int)" (??0TVersionCheck@@QEAA@H@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDetRunAction.obj : error LNK2019: unresolved external symbol "public: static void * __cdecl TStorage::ObjectAlloc
(unsigned __int64)" (?ObjectAlloc@TStorage@@SAPEAX_K@Z) referenced in function "public: void __cdecl SimpleDetRunAction
::NewOutputFile(class G4String)" (?NewOutputFile@SimpleDetRunAction@@QEAAXVG4String@@@Z) [C:\SimpleDet\build\SimpleDet.
vcxproj]
SimpleDetRunAction.obj : error LNK2019: unresolved external symbol "public: static void __cdecl TObject::operator delet
e(void *)" (??3TObject@@SAXPEAX@Z) referenced in function "int `public: void __cdecl SimpleDetRunAction::NewOutputFile(
class G4String)'::`1'::dtor$9" (?dtor$9@?0??NewOutputFile@SimpleDetRunAction@@QEAAXVG4String@@@Z@4HA) [C:\SimpleDet\bui
ld\SimpleDet.vcxproj]
SimpleDetRunAction.obj : error LNK2019: unresolved external symbol "public: static class TClass * __cdecl TClass::GetCl
ass(class type_info const &,bool,bool,unsigned __int64,unsigned __int64)" (?GetClass@TClass@@SAPEAV1@AEBVtype_info@@_N1
_K2@Z) referenced in function "public: class TBranch * __cdecl TTree::Branch<unsigned int>(char const *,unsigned int *,
int,int)" (??$Branch@I@TTree@@QEAAPEAVTBranch@@PEBDPEAIHH@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDetRunAction.obj : error LNK2019: unresolved external symbol "public: static enum EDataType __cdecl TDataType::Ge
tType(class type_info const &)" (?GetType@TDataType@@SA?AW4EDataType@@AEBVtype_info@@@Z) referenced in function "public
: class TBranch * __cdecl TTree::Branch<unsigned int>(char const *,unsigned int *,int,int)" (??$Branch@I@TTree@@QEAAPEA
VTBranch@@PEBDPEAIHH@Z) [C:\SimpleDet\build\SimpleDet.vcxproj]
SimpleDetRunAction.obj : error LNK2019: unresolved external symbol "protected: static class std::shared_ptr<struct std:
:atomic<class TDirectory *> > & __cdecl TDirectory::GetSharedLocalCurrentDirectory(void)" (?GetSharedLocalCurrentDirect
ory@TDirectory@@KAAEAV?$shared_ptr@U?$atomic@PEAVTDirectory@@@std@@@std@@XZ) referenced in function "public: void __cde
cl SimpleDetRunAction::SaveRootBegin(void)" (?SaveRootBegin@SimpleDetRunAction@@QEAAXXZ) [C:\SimpleDet\build\SimpleDet.
vcxproj]
SimpleDetRunAction.obj : error LNK2019: unresolved external symbol "public: __cdecl TTree::TTree(char const *,char cons
t *,int,class TDirectory *)" (??0TTree@@QEAA@PEBD0HPEAVTDirectory@@@Z) referenced in function "public: void __cdecl Sim
pleDetRunAction::SaveRootBegin(void)" (?SaveRootBegin@SimpleDetRunAction@@QEAAXXZ) [C:\SimpleDet\build\SimpleDet.vcxpro
j]
SimpleDetRunAction.obj : error LNK2019: unresolved external symbol "public: __cdecl TFile::TFile(char const *,char cons
t *,char const *,int)" (??0TFile@@QEAA@PEBD00H@Z) referenced in function "public: void __cdecl SimpleDetRunAction::NewO
utputFile(class G4String)" (?NewOutputFile@SimpleDetRunAction@@QEAAXVG4String@@@Z) [C:\SimpleDet\build\SimpleDet.vcxpro
j]
SimpleDetRunAction.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class TRandom * gRandom" (__i
mp_?gRandom@@3PEAVTRandom@@EA) referenced in function "public: __cdecl SimpleDetRunAction::SimpleDetRunAction(void)" (?
?0SimpleDetRunAction@@QEAA@XZ) [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libCore.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
 [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libImt.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
[C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libRIO.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
[C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libNet.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
[C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libHist.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
 [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libGraf.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
 [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libGraf3d.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x6
4' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libGpad.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
 [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libROOTDataFrame.lib : warning LNK4272: library machine type 'x86' conflicts with target machine t
ype 'x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libTree.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
 [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libTreePlayer.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type
 'x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libRint.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
 [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libPostscript.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type
 'x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libMatrix.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x6
4' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libPhysics.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x
64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libMathCore.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type '
x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libThread.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x6
4' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\root_v6.28.06\lib\libROOTVecOps.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type
 'x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\Qt\5.15.2\msvc2019\lib\Qt5OpenGL.lib : warning LNK4272: library machine type 'x86' conflicts with target machine typ
e 'x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\Qt\5.15.2\msvc2019\lib\Qt5PrintSupport.lib : warning LNK4272: library machine type 'x86' conflicts with target machi
ne type 'x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\Qt\5.15.2\msvc2019\lib\Qt5Widgets.lib : warning LNK4272: library machine type 'x86' conflicts with target machine ty
pe 'x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\Qt\5.15.2\msvc2019\lib\Qt5Gui.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type '
x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\Qt\5.15.2\msvc2019\lib\Qt5Core.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type
'x64' [C:\SimpleDet\build\SimpleDet.vcxproj]
C:\SimpleDet\build\Release\SimpleDet.exe : fatal error LNK1120: 9 unresolved externals [C:\SimpleDet\build\SimpleDet.vc
xproj]

However, it was able to do this before these errors popped up:


C:\SimpleDet\build>cmake --build . --config release
MSBuild version 17.7.2+d6990bcfa for .NET Framework

  1>Checking Build System
  Building Custom Rule C:/SimpleDet/CMakeLists.txt
  SimpleDet.cc
  SimpleDetActionInitialization.cc
  SimpleDetDetectorConstruction.cc
  SimpleDetDetectorMessenger.cc
  SimpleDetEventAction.cc
  SimpleDetHit.cc
  SimpleDetMagneticField.cc
  SimpleDetPhysicsList.cc
  SimpleDetPrimaryGeneratorAction.cc
  SimpleDetRunAction.cc
  SimpleDetSD.cc
  SimpleDetSteppingAction.cc
  SimpleDetSteppingVerbose.cc
  Generating Code...

In addition, I just want to make sure, I should still have that “FindRoot.cmake” file that I first showed you deleted correct?

OK this is an issue I will have to investigate and fix on Windows. Please replace

target_link_libraries(SimpleDet ${ROOT_LIBRARIES})

by

target_link_libraries(SimpleDet libCore libHist libGraf libGpad libGui libGuiHtml libHtml libTree libRIO)

(some libraries might be missing, but we’ll see later)

Yes, let’s see if you manage to build your project without this file.

Hello, I believe it showed the same errors when I tried again with replacing it like '…library machine type ‘x86’ conflicts with target machine type ‘x64’ ’

Here is what I have in that part in the CMakelists.txt

#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(SimpleDet SimpleDet.cc ${sources} ${headers})
target_link_libraries(SimpleDet ${Geant4_LIBRARIES})
#target_link_libraries(SimpleDet libCore libHist libGraf libGpad libGui libGuiHtml libHtml libTree libRIO)

target_link_libraries(SimpleDet libCore libHist libGraf libGpad libGui libGuiHtml libHtml libTree libRIO)

Unless you want me to try to install the 64 bit of ROOT or edit even more to this CMake list, I can certainly do that.

On Windows you have to make sure you configure and build the exact same architecture than the other dependencies. So ROOT and Geant must be of the same architecture and you must configure for the same architecture. I.e. if you want to build for 32 bit (assuming ROOT and Geant are both 32 bit), you must configure your project with:

cmake -G"Visual Studio 17 2022" -A Win32 -Thost=x64 [any option you need to pass] [location of your project source code]

And for 64 bit, replace -A Win32 by -A x64