# Implementing a Custom Class

**URL:** <https://root-forum.cern.ch/t/implementing-a-custom-class/15986>\
**Category:** ROOT\
**Created:** [April 27, 2013, 12:22am UTC](https://root-forum.cern.ch/t/implementing-a-custom-class/15986 "2013-04-27T00:22:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlam](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@jlam](https://root-forum.cern.ch/u/jlam)\
**Post date:** [April 27, 2013, 12:22am UTC](https://root-forum.cern.ch/t/implementing-a-custom-class/15986/1 "2013-04-27T00:22:29Z")

</div>

Hello Root Support,  
I am having some trouble understanding how to properly compile a program which incorporates a class that extends off TObject.  
I have a custom class which extends off of TObject called CoreasEvent. Within my main program, I read a tree that stores this custom class. My classes are able to compile into object files just fine, but the problem arises when I attempt to link the objects and create an executable. Attempting to do so results in the following errors:

```auto
g++ -O vector.o assa.o `/u/osgstorage/anita/root/bin/root-config --glibs` -o assa.exe
assa.o: In function `__static_initialization_and_destruction_0':
~/scripts/assa/assa_root/assa.cc:45: undefined reference to `CoreasEvent::CoreasEvent()'
assa.o: In function `getCRSignal(TTree*, double, double, double, double, double, double, double, double, double, double, double, std::vector<double, std::allocator<double> >&)':
~/scripts/assa/assa_root/assa.cc:811: undefined reference to `CoreasEvent::getOffAngles()'
collect2: ld returned 1 exit status
make: *** [assa.exe] Error 1
```

The second error especially confuses me because I have confirmed getOffAngles is indeed a function of CoreasEvent.  
Another question: what is the difference between using a shared library generated by running .L myclass.cc+ and manually creating your own dictionary using rootcint and a Linkdef file?  
Any help would be appreciated, thank you!

---

<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:** [April 27, 2013, 6:26am UTC](https://root-forum.cern.ch/t/implementing-a-custom-class/15986/2 "2013-04-27T06:26:19Z")

</div>

[ROOT User’s Guide - Chapter 15. Adding a Class](http://root.cern.ch/download/doc/ROOTUsersGuideHTML/ch15.html)  
[ROOT User’s Guide - Chapter 15. Adding a Class - Adding a Class with a Shared Library](http://root.cern.ch/download/doc/ROOTUsersGuideHTML/ch15s05.html)  
[ROOT User’s Guide - Chapter 15. Adding a Class - Adding a Class with ACLiC](http://root.cern.ch/download/doc/ROOTUsersGuideHTML/ch15s06.html)  
[ROOT - Frequently Asked Questions - How to generate a dictionary](http://root.cern.ch/drupal/faq#n676)  
[url][Adding a class: hand holding requested](https://root-forum.cern.ch/t/adding-a-class-hand-holding-requested/13893/2)  
[url][Problems Building a class into a shared library](https://root-forum.cern.ch/t/problems-building-a-class-into-a-shared-library/14758/3)  
[url][Adding Classes in ACLiC](https://root-forum.cern.ch/t/adding-classes-in-aclic/15817/2)  
[url][Root Tree Custom Objects](https://root-forum.cern.ch/t/root-tree-custom-objects/15878/2)  
[Using ROOTCINT](http://root.cern.ch/root/RootCintMan.html)  
[Selecting Dictionary Entries: Linkdef.h](http://root.cern.ch/drupal/content/selecting-dictionary-entries-linkdefh)  
[Interacting with Shared Libraries: rootcint](http://root.cern.ch/drupal/content/interacting-shared-libraries-rootcint)  
[Adding Your Class to ROOT: ClassDef](http://root.cern.ch/drupal/content/adding-your-class-root-classdef)  
[url][Simple way to create and merge shared libraries?](https://root-forum.cern.ch/t/simple-way-to-create-and-merge-shared-libraries/11652/6)

---

<div class="post-metadata">

**Author:** ![jlam](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/839c29/32.png) [@jlam](https://root-forum.cern.ch/u/jlam)\
**Post date:** [April 29, 2013, 8:18pm UTC](https://root-forum.cern.ch/t/implementing-a-custom-class/15986/3 "2013-04-29T20:18:41Z")

</div>

Hi Wile E., thank you for responding.  
I read through your links and wanted to make my question a little bit more specific:  
In what cases do I need to generate/compile a dictionary? If I already generated a .so file for CoreasEvent within root, can I use that .so file or do I still need to generate a dictionary for CoreasEvent and link it when compiling my executable.

---

<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:** [April 29, 2013, 8:55pm UTC](https://root-forum.cern.ch/t/implementing-a-custom-class/15986/4 "2013-04-29T20:55:02Z")

</div>

It is quite possible that you can reuse the shared library which ROOT generated (just try to add it to the linking command line, right after your object files).
