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

8.9k views Asked by At

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

2

There are 2 answers

0
nneonneo On

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

0
InstictV On

I had the same problem and I just solved it installing these libraries: "libroot-*", "root-plugin-*","ttf-root-installer".` I find the answer on ROOT forum if you interested, here is the link: https://root.cern.ch/phpBB3/viewtopic.php?t=16352. To install the library, you can write on terminal the follow command line:

sudo apt-get install nameoflibrary