Gcc to compile root macro -> 'undefined reference to' error

Dear rooters,

I’m trying to use g++ directly to compile my code and produce a stand-alone executable. Unfortunately I have run into an issue I don’t know how to solve. This is what I’m doing with my code:

g++ lvis_mol_lens.cxx read_inputs.cxx -o lvis_mol_lens -Wall -I /opt/root/include/root/ -L /opt/root/lib/root/

After this I’m getting this type of output:

/tmp/ccDvSTwe.o: In function `main':
lvis_mol_lens.cxx:(.text+0x37a1): undefined reference to `TVector3::TVector3(double, double, double)'
lvis_mol_lens.cxx:(.text+0x3828): undefined reference to `TVector3::TVector3(double, double, double)'
lvis_mol_lens.cxx:(.text+0x38a3): undefined reference to `TRotation::TRotation()'
lvis_mol_lens.cxx:(.text+0x3924): undefined reference to `TRotation::TRotation()'
lvis_mol_lens.cxx:(.text+0x3a55): undefined reference to `TVector3::SetTheta(double)'
lvis_mol_lens.cxx:(.text+0x3a9c): undefined reference to `TVector3::SetPhi(double)'
lvis_mol_lens.cxx:(.text+0x3aef): undefined reference to `TVector3::SetPhi(double)'
lvis_mol_lens.cxx:(.text+0x3b23): undefined reference to `TVector3::Unit() const'
....

Despite the fact the output doesn’t point to any line in particular, I’m certain the first few errors correspond to the following part in my code

....
	TVector3 kmol[4];					// Wavevectors molasses

	TVector3 w0molpos[4];				// Molasses beam waist position from center molasses reference frame

	TRotation molrotz[4];				// Rotations to transform from center molasses reference frame to beam frame

	TRotation molrotx[4];

	double molwidth = 0;					// Average beam width at molasses center

	int i;

	for ( i = 0 ; i < nmolbeams ; i ++ )
	{
		kmol[i].SetX( 1 );

		kmol[i].SetMag( 1 / lam );

		kmol[i].SetTheta( pi / 2 );

		if ( i < 2 )

			kmol[i].SetPhi( i * pi );

		else

			kmol[i].SetPhi( ( 2 * i - 3 ) * pi / 2 );

		w0molpos[i] = - kmol[i].Unit();

....

My gut feeling is: “this is me not understand C++”

Please help!, any nudge in the right direction is greatly appreciated!

Thanks

Hi,

You would need to link your executable against the ROOT library that you are using, so in your case:`root-config --libs` -lPhysics(the call to root-config is to get the list of default ROOT library).

Cheers,
Philippe.

[quote=“pcanal”]Hi,

You would need to link your executable against the ROOT library that you are using, so in your case:`root-config --libs` -lPhysics(the call to root-config is to get the list of default ROOT library).

Cheers,
Philippe.[/quote]

Thanks!, this helped a lot, but it is not clear (from the list below) what should I use for the geometry library?

$ root-config --libs
-L/opt/root/lib/root -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lz -pthread -lm -ldl -rdynamic

Hi,

-lGeom ? In the reference guide (see for example root.cern.ch/root/html/TGeoBBox.html) you can see the library name in the box in the top right of the page.

Cheer,s
Philippe.

[quote=“pcanal”]Hi,

-lGeom ? In the reference guide (see for example root.cern.ch/root/html/TGeoBBox.html) you can see the library name in the box in the top right of the page.

Cheer,s
Philippe.[/quote]

I see. Thanks again.