Compiling Root script with g++


I am trying to compile a Root script externally with g++ so as to make a stand alone executable. As an initial step I am trying to just compile (

#include "TTree.h"
int main()
return 0;

However I get the following error that I can’t figure out:
g++ -c -g -Wall root-config --cflags -o main.o
g++ root-config --glibs main.o -o main
main.o: In function __static_initialization_and_destruction_0': /usr/local/include/root/TVersionCheck.h:34: undefined reference toTVersionCheck::TVersionCheck(int)'
collect2: ld returned 1 exit status
make: *** [main] Error 1

I am using the following makefile:

CFLAGS=-c -g -Wall root-config --cflags
LDFLAGS=root-config --glibs
main :

$(CC) $(LDFLAGS) $(OBJECTS) -o $@

$(CC) $(CFLAGS) $< -o $@

rm ./~ ./.o

Thank you in advance,

This should work.

Do you by chance have another ROOT installation early in you LD_LIBRARY_PATH, i.e. before the one installed to /usr/local?

LDFLAGS=root-config --ldflags
LDLIBS=root-config --glibs

I don’t think I have any previous installs. This is what is in the LD_LIBRARY_PATH

When I try to compile with out make:
g++ root-config --ldflags -o main root-config --glibs fatal error: TTree.h: No such file or directory
compilation terminated.

CXX=root-config --cxx
CXXFLAGS=root-config --cflags
LDFLAGS=root-config --ldflags
LDLIBS=root-config --glibs

… either …

$(CXX) $(CXXFLAGS) -W -Wall -o $@ $^ $(LDLIBS)

… or …

$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

$(CXX) $(CXXFLAGS) -W -Wall -c $<

That fixed it

Thank you