"undefined reference" when link

I install root(5.34/04) on i686 machine and under ubuntu 12.10. However, when I try to compile the codes I have successfully run on another computer, there are bunch of errors as follows(part of the errors), :frowning:

regenerate.o: In function main': regenerate.cpp:(.text+0x742): undefined reference toTMath::Nint(double)'
regenerate.cpp:(.text+0x944): undefined reference to TVector3::TVector3(double, double, double)' regenerate.cpp:(.text+0x972): undefined reference toTVector3::TVector3(double, double, double)'
regenerate.cpp:(.text+0x9a0): undefined reference to TVector3::TVector3(double, double, double)' regenerate.cpp:(.text+0x9c2): undefined reference tooperator-(TVector3 const&, TVector3 const&)'
regenerate.cpp:(.text+0x9eb): undefined reference to TVector3::~TVector3()' regenerate.cpp:(.text+0xa03): undefined reference toTVector3::Unit() const’
regenerate.cpp:(.text+0xa2c): undefined reference to TVector3::~TVector3()' regenerate.cpp:(.text+0xa69): undefined reference toTVector3::Unit() const’
regenerate.cpp:(.text+0xa92): undefined reference to TVector3::~TVector3()' regenerate.cpp:(.text+0xaaa): undefined reference tooperator*(TVector3 const&, TVector3 const&)'
regenerate.cpp:(.text+0xac8): undefined reference to operator*(TVector3 const&, TVector3 const&)' regenerate.cpp:(.text+0xae6): undefined reference tooperator*(TVector3 const&, TVector3 const&)'
regenerate.cpp:(.text+0xcb1): undefined reference to TRandom::Uniform(double, double)' regenerate.cpp:(.text+0xd1f): undefined reference toTVector3::TVector3(double, double, double)'
regenerate.cpp:(.text+0xd39): undefined reference to TVector3::RotateY(double)' regenerate.cpp:(.text+0xd4f): undefined reference toTVector3::operator()(int)'
regenerate.cpp:(.text+0xd6d): undefined reference to TVector3::operator()(int)' regenerate.cpp:(.text+0xd8b): undefined reference toTVector3::operator()(int)‘
regenerate.cpp:(.text+0xdc1): undefined reference to TVector3::operator()(int)' regenerate.cpp:(.text+0xddf): undefined reference toTVector3::operator()(int)’

The compile codes I use is:
g++ -c regenerate.cpp root-config --cflags
g++ root-config --glibs -o regenerate regenerate.o

And the results of “root-config --cflags --glibs” is
-pthread -m32 -I/usr/local/include/root -L/usr/local/lib/root -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic

Thanks very much.

root-config --cxx --cflags -o regenerate regenerate.o root-config --glibs

Thanks so much! Although I don’t understand why this works.

The output of “root-config --cxx --cflags” is
g++ -pthread -m32 -I/usr/local/include/root

Hence the difference between the right code and mine are the head files.

However, I have also tried
g++ -o regenerate root-config --cflags --glibs regenerate.cpp
and still get the same error information. Just get confused.

You saved my day! Thanks again. :stuck_out_tongue:

Either in two steps:
root-config --cxx --cflags -c SomeApplication.cxx
root-config --cxx --ldflags -o SomeApplication SomeApplication.o root-config --glibs
or in one step:
root-config --cxx --cflags -o SomeApplication SomeApplication.cxx root-config --glibs