Compilation error in pythia 8

i had modified program) as
when i tried to compile it using

  g++ -O2 -ansi -pedantic -W -Wall -Wshadow -I$PYTHIA8/include -I$ROOTSYS/include -o mainz02 

i got error as:
collect2: ld returned 1 exit status

my program is: (1.49 KB)


You have to link against libPythia8 (-L$PYTHIA8/lib -lPythia8) and some of the ROOT libraries (using ‘root-config --glibs’). See for example [url= thread[/url], or just search on this forum, there are probably several examples…

And please, don’t post several times the same question in different threads.

And you should probably ask one of your colleagues to explain how all this work. It is much better to look at this in front of a computer than exchanging posts on a forum…

Cheers, Bertrand.

should i change my makefile in pythia/examples???

This is one option. You can also make a new one, or type directly from the command line…

can you tell me the command line i should use??

i used the code:

g++ -O2 -ansi -pedantic -W -Wall -Wshadow `root-config --glibs` -L$PYTHIA8/lib -I$PYTHIA8/include -I$ROOTSYS/include -o mainz02

i am still getting the same error

But you should ask your colleagues, really...

But you should ask your colleagues, really…

Thanks :slight_smile:
my colleagues are not expert in c++.They are doing physics part.I had already asked them.
i used

It created a file mainz02 but not a file with extension .exe

Plzzzz someone help :frowning:

This is normal on Linux… #-o Just execute it…


mainz02.exe would be on Windows. NB if you want you can rename it:

mv mainz02 mainz02.exe :-k

i used

i got error as:
./mainz02: error while loading shared libraries: cannot open shared object file: No such file or directory

i then used

then i tried to get output using

i again got error as:
./mainz02.exe: error while loading shared libraries: cannot open shared object file: No such file or directory

plzz help :frowning:

You know you should really try to search and find solutions by yourself at some point… There are several posts on this forum asking the same kind of question, and you can easily search the forum with the “search” entry on the top right corner…
And to answer your question (just in case you didn’t find it by yourself), you have this error because $ROOTSYS/lib is not in the LD_LIBRARY_PATH. You have to execute the “” (or thisroot.csh) script located in $ROOTSYS/bin, as explained for example in Installing ROOT from Source page.
And to make sure you read the right part of it, here is what it says:

Add bin/ to PATH and lib/ to LD_LIBRARY_PATH. For the sh shell family do:

. bin/ and for the csh shell family do: source bin/thisroot.csh
And please, keep the original file name, and don’t rename it with .exe [-o<

But i had built root using fixed location installation.
I had used

when i used

i got output as:
root: /etc/root /usr/local/bin/root.exe /usr/local/bin/root /usr/local/lib/root

i also has root directory in my Downloads directory as:

i also had added these lines to my .bashrc file

source /home/raman/Downloads/root/bin/ export PYTHIA8=/home/raman/Downloads/pythia8176 export PYTHIA8DATA=$PYTHIA8/xmldoc export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/raman/Downloads/pythia8176/lib export ROOTSYS=/home/raman/Downloads/root export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/raman/Downloads/root/lib export PATH=$ROOTSYS/bin:$PATH

i also had used source .bashrc after adding these lines.

Could you post the result of “echo $PATH” and “echo $LD_LIBRARY_PATH”?

the output of


and the output of


See[quote=“raman”]and the output of
See? [color=#0000FF]/home/raman/Downloads/root/lib[/color] is missing from your $LD_LIBRARY_PATH… If you fix that everything will work.

now the output of


and my program is working now.