# Error on loading shared library

**URL:** <https://root-forum.cern.ch/t/error-on-loading-shared-library/37624>\
**Category:** Newbie\
**Created:** [January 18, 2020, 8:41am UTC](https://root-forum.cern.ch/t/error-on-loading-shared-library/37624 "2020-01-18T08:41:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ydlawther](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/48db29/32.png) [@ydlawther](https://root-forum.cern.ch/u/ydlawther)\
**Post date:** [January 18, 2020, 8:41am UTC](https://root-forum.cern.ch/t/error-on-loading-shared-library/37624/1 "2020-01-18T08:41:15Z")

</div>

I’m new to root and C++ and Linux…  
I have a MyClass.h and a MyClass.C file.  
If I try to type

```auto
.x /Users/burial/Applications/root_v6.18.04/MyClass.C

```

I can successfully define

```auto
MyClass* t = new MyClass()

```

But when I try to run a .C file as shown:

```auto
#include "/Users/burial/Applications/root_v6.18.04/MyClass.h"

//.x /Users/burial/Applications/root_v6.18.04/MyClass.C

int main()
{
	MyClass* t = new MyClass();
	TTree *tgood = new TTree("tgood","");
	double pt;
	tgood->Branch("pt", &pt, "pt/D");
	int nTracks = t->Event_multi;
	t->GetEntry(1);
	nTracks = t->Event_multi;

	for(int i=0; i<nTracks; i++) {

			double px = t->Px[i];
			double py = t->Py[i];
			double pz = t->Pz[i];
			TVector3 mom(px,py,pz);
			pt = mom.Perp();

			tgood->Fill();
		}

		TFile f("/Users/burial/Desktop/test.root", "recreate");
		tgood->Write();
		f.Close();
                return 0;

}

```

It couldn’t work and shows like:

```auto
root [2] .x /Users/burial/Desktop/test.cpp
IncrementalExecutor::executeFunction: symbol '_ZN8TVector3C1Eddd' unresolved while linking [cling interface function]!
You are probably missing the definition of TVector3::TVector3(double, double, double)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZN7MyClassC1EP5TTree' unresolved while linking [cling interface function]!
You are probably missing the definition of MyClass::MyClass(TTree*)
Maybe you need to load the corresponding shared library?

```

I don’t know how to load the corresponding shared library. I tried the following command and it didn’t work:

```auto
.x /Users/burial/Applications/root_v6.18.04/MyClass.h++
ROOT_prompt_3:1:1: error: expected expression
/Users/burial/Applications/root_v6.18.04/MyClass.h++
^
ROOT_prompt_3:1:2: error: use of undeclared identifier 'Users'
/Users/burial/Applications/root_v6.18.04/MyClass.h++
 ^
ROOT_prompt_3:1:8: error: use of undeclared identifier 'burial'
/Users/burial/Applications/root_v6.18.04/MyClass.h++
       ^
ROOT_prompt_3:1:15: error: use of undeclared identifier 'Applications'
/Users/burial/Applications/root_v6.18.04/MyClass.h++
              ^
ROOT_prompt_3:1:28: error: use of undeclared identifier 'root_v6'
/Users/burial/Applications/root_v6.18.04/MyClass.h++

```

What can I do to load the Corresponding shared library?

And there’s two other little questions, when I write a .C file and try to run it in root, should I put it in the same directory where root is? And I just tried type “echo $ROOTSYS”, it just shows blank, but I can still access the tutorials by “cd $ROOTSYS/tutorials” what’s wrong with this?

Thank you in advance.  
(English is not my native language, if there’s some grammar mistakes please forgive them.;))

\_ROOT Version:6.18/04  
\_Platform:Mac OSX Catalina 10.15.2  
\_Compiler:Mac OSX Terminal

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 18, 2020, 10:19am UTC](https://root-forum.cern.ch/t/error-on-loading-shared-library/37624/2 "2020-01-18T10:19:53Z")

</div>

`gSystem->Load("libPhysics"); // TVector3`

---

<div class="post-metadata">

**Author:** ![ydlawther](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/48db29/32.png) [@ydlawther](https://root-forum.cern.ch/u/ydlawther)\
**Post date:** [January 18, 2020, 10:38am UTC](https://root-forum.cern.ch/t/error-on-loading-shared-library/37624/3 "2020-01-18T10:38:30Z")

</div>

Where should I add this line, does it need to be included in the main function?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 18, 2020, 10:41am UTC](https://root-forum.cern.ch/t/error-on-loading-shared-library/37624/4 "2020-01-18T10:41:39Z")

</div>

You need to execute it before you try to call your macro (on the ROOT prompt).

---

<div class="post-metadata">

**Author:** ![ydlawther](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/48db29/32.png) [@ydlawther](https://root-forum.cern.ch/u/ydlawther)\
**Post date:** [January 18, 2020, 10:47am UTC](https://root-forum.cern.ch/t/error-on-loading-shared-library/37624/5 "2020-01-18T10:47:04Z")

</div>

Do I need to put the .C file(my macro) in the …/root/macro folder too? Or this doesn’t matter?
