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!
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)
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…
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?
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:
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?
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]