Loading a home grown shared library in root

Hi, I have a shared library that I want to use in my root script. Do I need to do something special in the classes in my home grown library for my root script to use it?

For simplicity I create a simple class and created a *.so out of it. The class looks something like this:

accuracy.h:

[code]#ifndef ACCURACY_H
#define ACCURACY_H
#include

class accuracy {
public:
accuracy():acc(0.0) { }
virtual ~accuracy() { }

void setAcc(const double &d);
void print(const char *str) {
std::cout << str << " where acc=" << acc << std::endl;
}

private:
double acc;
};

#endif // ACCURACY_H[/code]

and accuracy.cpp:

[code]#include “accuracy.h”

using namespace std;

void accuracy::setAcc(const double &d) {
acc=d;
return;
}[/code]

So just from these two files I created libAccuracy.so

I then wrote a simple root script test.C:

[code]#include “TInterpreter.h”
#include “TCanvas.h”
#include “TFile.h”
#include “TTree.h”
#include “TBrowser.h”
#include “TH1.h”
#include “TH2.h”
#include “TRandom.h”
#include “TClassTable.h”
#include “TSystem.h”
#include “TROOT.h”
#if defined(CINT) && !defined(MAKECINT)
#includelibAccuracy.so
#else
#include “accuracy.h”
#endif
#include

using namespace std;

void test() {
// load other dependent libs
gSystem->Load(“libAccuracy”);
accuracy acc;
acc.print(“hello world”);
acc.setAcc(56.2);
acc.print(“This is the end!”);

return;
}[/code]

Yet, when I ran this in root, I got this error:

[code]ROOT 5.34/10 (v5-34-10@v5-34-10, Oct 31 2013, 10:45:43 on linuxx8664gcc)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .x test.C
Note: File “/home/jade/bbox/cpp/./libAccuracy.so” already loaded
Error: Invalid type ‘accuracy’ in declaration of ‘acc’ test.C:25:
Error: Symbol accuracy acc is not defined in current scope test.C:25:
*** Interpreter error recovered ***
root [1] [/code]

So what am I doing wrong? Of course ultimately I plan to load a much larger C++ library than this but wanted to test it for something very simple first.

For root to recognize this accuracy class, must it inherit from TObject? Even if all the class offers are just functional utilities (no trees, etc.)?

I’ve run into a similar issue trying to get ROOT to run locally on my laptop. Was this problem ever solved?

Hi @dgillcri - you have resurrected a 4 year old post :slight_smile: Can you open a new topic posting the error messages you get?