How can I compile a C++ program with root library includes using g++?

Rodrigo Campos de Carvalho picture Rodrigo Campos de Carvalho · Nov 29, 2014 · Viewed 7.7k times · Source

I have written a C++ program (mainPixelDet1.C that uses a class defined in PixelDet1.C), that works in root's interactive mode.

But now I want to compile it outside root, using g++.

Here's what I write on the Terminal:

g++ -o main mainPixelDet1.C PixelDet1.C `root-config --cflags --glibs`

And here's what I get:

/usr/bin/ld: cannot find -lGraf3d
usr/bin/ld: cannot find -lPostscript
/usr/bin/ld: cannot find -lPhysics
collect2: error: ld returned 1 exit status

Answer

nneonneo picture nneonneo · Nov 29, 2014

You'll have to also include --ldflags to root-config, so that root-config will supply the necessary library flag arguments.