Unable to compile root programs outside root environment

Please provide the following information:


ROOT Version (5.34.36):
Platform, compiler (Windows 10):


(I am using root 5.34.36 (on windows 10)
I am unable to compile this code outside of root.
This is my code ( I save it as a .cpp file and try to execute it outside root using g++ (filename).cpp) and i get the error :

#include <iostream>
#include <TObject.h>
#include <TROOT.h>
#include<TFile.h>
#include <TTree.h>
using namespace std;
int main ()

{
cout << “Hellow World” << endl;
return 0;
}

C:\Users\DEBAJY~1\AppData\Local\Temp\ccgInqnq.o:rootpr.cpp:(.text+0x92): undefined reference to `TVersionCheck::TVersionCheck(int)’
collect2.exe: error: ld returned 1 exit status

Hi,

Which version of ROOT do you use exactly? if it’s the native one, you have to compile with cl.exe, not g++
And see also Posting code? Read this first!

Cheers, Bertrand.

also: how do you compile it? (i.e. please post the exact command line you use to compile this. it seems to me you may be missing mandatory linkopts)

My filename is rootpr.cpp and i use

g++ rootpr.cpp -o rootpr.exe

I am using root 5.34.36 on windows 10

You’d need to wire in ‘root-config --cflags --libs’ into the compilation invocation.
(At least on Unix)

So I compile with

g++ rootpr.C -o rootpr.exe ‘root-config --cflags --libs’

and I get the error :
g++: error: `root-config: No such file or directory
g++: error: unrecognized command line option ‘–cflags’
g++: error: unrecognized command line option ‘–libs’’

Sorry, I am typing from my phone.
I am not a Windows expert and I don’t know if the backticks ` work like on Unix.
Run the root-config command I alluded to earlier and copy paste the result in your compilation invocation.

I tried compiling using

g++ rootpr.C -o rootpr.exe `root-config --cflags --libs`

I get the same error

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.