4
votes

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
Add the -L specifying the directory where those libraries are located. If they are in different directories, you might need more than one -LJoe
Side note: C++ programs should be written in files that use the .cpp extension, for clarity and to tell the compiler easily whether it needs to compile as c++. .c tends to be used for Cfoips
Thank you very much! @Joe It worked :)Rodrigo Campos de Carvalho
@foips this convention doesn't necessarily hold for ROOT. In particular, the interactive mode isn't standards-complaint C++, it's just something that borrows heavily form the syntax. Personally, I'd prefer that code written for interactive ROOT have the .C extension, since it emphasizes where it came from.Shep
@Shep Oh, for the life of me I don't think I'd seen the ROOT tag in this when I originally posted, apologiesfoips

2 Answers

2
votes

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

1
votes

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