Geant4 and ROOT and CMake and VS2013 under Windows 7

Dear ROOT community,

I’m using Geant4 to do some physics simulations. In my Geant4 applications I want to fill some histograms and trees. However I have a problem linking ROOT to CMake.

I’m using CMake (3.0.2, GUI) to generate a MS VS Solution file, and afterwards build it with VS 2013 Express Desktop.

When building with VS I get the error messages:

Error 1 error LNK2019: unresolved external symbol "public: __cdecl TVersionCheck::TVersionCheck(int)" (??0TVersionCheck@@QEAA@H@Z) referenced in function "void __cdecl `dynamic initializer for 'gVersionCheck''(void)" (??__EgVersionCheck@@YAXXZ) D:\RS_work\Geant4\geant4_10_00_p3_install\share\Geant4-10.0.3\examples\basic\B7_build\B7Analysis.obj exampleB7 Error 2 error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionCheck(int)" (??0TVersionCheck@@QEAA@H@Z) D:\RS_work\Geant4\geant4_10_00_p3_install\share\Geant4-10.0.3\examples\basic\B7_build\B7EventAction.obj exampleB7 Error 3 error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionCheck(int)" (??0TVersionCheck@@QEAA@H@Z) D:\RS_work\Geant4\geant4_10_00_p3_install\share\Geant4-10.0.3\examples\basic\B7_build\B7RunAction.obj exampleB7 Error 4 error LNK2001: unresolved external symbol "public: __cdecl TVersionCheck::TVersionCheck(int)" (??0TVersionCheck@@QEAA@H@Z) D:\RS_work\Geant4\geant4_10_00_p3_install\share\Geant4-10.0.3\examples\basic\B7_build\B7SteppingAction.obj exampleB7 Error 5 error LNK1120: 1 unresolved externals D:\RS_work\Geant4\geant4_10_00_p3_install\share\Geant4-10.0.3\examples\basic\B7_build\Release\exampleB7.exe exampleB7

Which is the same error message I get as if no ROOT libraries are linked! I’m getting the ROOT system variables and directories and so on from “FindROOT.cmake” (see attachmant) and then pass them on to my “CMakeLists.txt” file. When building with VS 2013 and having a look in my linker properties

Properties -> Linker -> Command Line

I see that all my lib paths are set correctly.

However apparently I’m missing something… can someone help me out here? I’ve searched the ROOT talk forum and other web pages for quite some time, but I can’t solve my problem and I guess I really need some help. If you need more information about my code and so on, please let me know by posting.

Thanks & best regards,
Robert
FindROOT.cmake.txt (7.71 KB)
CMakeLists.txt (3.29 KB)

Hi Robert,

In FindROOT.cmake, this statement is going to fail:

find_program(ROOT_CONFIG_EXECUTABLE root-config PATHS ${ROOTSYS}/bin $ENV{ROOTSYS}/bin) Since on Windows, there is no executable called root-config
So you may have to specify the libraries by hand…

Cheers, Bertrand.

Another thing:

When I try to run a console application (only a very minimalisitc code):

[code]// ROOT_incl.cpp : Defines the entry point for the console application.
//

#include “stdafx.h”
#include

#include “TString.h”

using namespace std;

int main()
{
TString s1;
s1 = “World”;
cout << “Hello,” << s1 << “!” << endl;
cout << “Bye,” << s1 << “!” << endl;

return 0;

}
[/code]

This example is for ROOT and VS2013 only, to even see if I can get it to run (Geant4 and VS works, ROOT and VS not yet). Here I manually set the include and lib paths for my project. In the linker options of my project I add

to the additional options. Now the code compiles, but when I run it, I get the error that “libCore.dll is missing”. However, when I try to execute ROOT macros (.C files) they work fine.

Does anyone have some hints for me?

Thanks & best regards,
Robert

Hi,

Add “D:\ROOT_CERN\root_v5.34.21\bin” to your path
You can also call “D:\ROOT_CERN\root_v5.34.21\bin\thisroot.bat” to properly setup your environment variables (only valid for the command prompt from which it is run)

Cheers, Bertrand.

Hi Bertrand,

I got VS with ROOT working. I had to run the executable as administrator, since my system variables can only be run as such. This is due to the companys computer system.

However the problem with Geant4, ROOT and VS still persists.

Thanks & cheers,
Robert

Hi Robert,

Is it still failing the same way?

Cheers, Bertrand.

Hi Bertrand,

no it is not failing the same way. I get the error postet in my first original message, telling me somehting about the “TVersionChecker”. I get this error when I put e.g.

in my analyisis code. I’ve also tried it with other ROOT classes, such as TVector3… I get the same error. It seems I have “no libraries” inside my Geant4 ROOT VS project (?). Also in my folder “external dependencies” the ROOT headers do not show up, even though I’ve included them in my VS project properties. It seems that my project does not recognize ROOT.

However when I try to include ROOT in a simple VS console application it works fine. Can this be an error due a false usage of 32bit and/or 64bit packages?

Thanks & cheers,
Robert

Hi Robert,

64 bit is not yet supported by ROOT on Windows. You have to build in 32 bit. And BTW, do you see the list of ROOT libraries in your Visual Studio solution?

Cheers, Bertrand.

Hi Bertrand,

the working console application is built with the “Win32” option …
And, when trying to include it into my Geant4 application, the build option is “x64” …

So in total I should build all applications in 32bit?

No, I don’t see them. The folder “External Dependencies” only shows my Geant4 header files - if that is what you mean :slight_smile:

Thanks & cheers,
Robert

[quote=“Rschaefer”]So in total I should build all applications in 32bit?[/quote]Absolutely, yes. You have to use the exact same architecture, and same configuration (i.e. don’t mix debug/release mode and don’t mix runtime libraries)

[quote=“Rschaefer”]No, I don’t see them. The folder “External Dependencies” only shows my Geant4 header files - if that is what you mean [/quote]No, I mean the libraries (should be listed under “Input” section of the “Linker” Configuration property)

Cheers, Bertrand.

Hi Bertrand,

well I figured out that I compiled and built Geant4 under 64bit build, now I’m trying to link it with ROOT under 32bit, which does not work. Now I’ll reinstall/rebiuld Geant4 with 32bit and try including ROOT again.
I will tell you whether I suceedd

Well, in the linker tab the ROOT libraries are not directly displayed, but in the command line I have

listed, so they should be included. Just the header files dont appear in the “External Dependencies” folder :slight_smile:

Cheers,
Robert

[quote=“Rschaefer”]Well, in the linker tab the ROOT libraries are not directly displayed, but in the command line I have

“D:\ROOT_CERN\root_v5.34.21\lib*.lib;”

listed, so they should be included. Just the header files dont appear in the “External Dependencies” folder
[/quote]Not sure this is going to work… But anyway, you can still add the files by hand in the input section, at least to be sure it builds properly…

Cheers, Bertrand.

Hi Bertrand,

now it does work and compile. So I was just mixing up 64bit and 32bit of several programs (Geant4, ROOT, Qt).

The only leftover error I have is when I run the “.exe” I get:

But maybe reinstalling Qt does work or something like that.

I guess you can close the thread now.

Thanks again & best regards,
Robert

Hi Robert,

You’re welcome! Glad to see you solved the problem! And about Qt, I suppose you have to use the exact same version everywhere… Good luck! :wink:

Cheers, Bertrand.