Trouble with loading shared library - strange behaviour

Dear all,

I have a shared library with the classes event and hit (hit represents a pulse, it has members as integral charge, amplitude, etc; event is the whole profile from a scop, it has as members a vector of hits, pedestal, threshold, noise, etc). I wrote a short test analysis macro to make a few histograms and see whether everything goes smoothly when loading the .so file and reading the data from a output TFile instance (it has a TTree instance with a event branch): it does not.

I load the .so file in a script but the compilatiosn fails because ROOT says the classes weren’t declared. On ROOT shell,

root [0] .L readData.C++
Info in <TUnixSystem::ACLiC>: creating shared library /eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C: In function ‘void readData()’:
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:44: error: ‘event’ was not declared in this scope
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:44: error: ‘event_687’ was not declared in this scope
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:44: error: expected type-specifier before ‘event’
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:44: error: expected `;' before ‘event’
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:51: error: ‘hit’ was not declared in this scope
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:51: error: ‘firstHit_687’ was not declared in this scope
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:53: error: ‘hit’ cannot appear in a constant-expression
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:53: error: template argument 1 is invalid
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:53: error: template argument 2 is invalid
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:53: error: invalid type in declaration before ‘;’ token
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:75: error: request for member ‘at’ in ‘hits_687’, which is of non-class type ‘int’
/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C:92: error: request for member ‘clear’ in ‘hits_687’, which is of non-class type ‘int’
g++: /eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/readData_C_ACLiC_dict.o: No such file or directory
Error in <ACLiC>: Compilation failed!

However, if I load the shared library on the shell, it seems it works because ROOT recognises the classes:

root [0] gSystem->Load("");
root [1] .class hit
class hit
 size=0x1c LINE:-1
List of base class--------------------------------------------------------
List of member variable---------------------------------------------------
Defined in hit   -1 0xffffffff private: long G__virtualinfo   -1 0xffffffff private: int start   -1 0xffffffff private: int width   -1 0xffffffff private: double maximum   -1 0xffffffff private: double integral //replace minimum with maximum   -1 0x0        private: static TClass* fgIsA
List of member function---------------------------------------------------
filename       line:size busy function type and name  (in hit)   -1:-1   0 public: virtual void ~hit(void);   -1:-1   0 public: hit hit(void);   -1:-1   0 public: void init(int,int,double,double);   -1:-1   0 public: void print(void);   -1:-1   0 public: int getStart(void);   -1:-1   0 public: int getWidth(void);   -1:-1   0 public: double getMaximum(void);   -1:-1   0 public: double getIntegral(void);   -1:-1   0 public: static TClass* Class(void);   -1:-1   0 public: static const char* Class_Name(void);   -1:-1   0 public: static Version_t Class_Version(void);   -1:-1   0 public: static void Dictionary(void);   -1:-1   0 public: virtual TClass* IsA(void) const;   -1:-1   0 public: virtual void ShowMembers(TMemberInspector& insp);   -1:-1   0 public: virtual void Streamer(TBuffer& b);   -1:-1   0 public: void StreamerNVirtual(TBuffer& b);   -1:-1   0 public: static const char* DeclFileName(void);   -1:-1   0 public: static int ImplFileLine(void);   -1:-1   0 public: static const char* ImplFileName(void);   -1:-1   0 public: static int DeclFileLine(void);   -1:-1   0 public: hit hit(const hit&);   -1:-1   0 public: hit& operator=(const hit&);

When I just .L readData.C, it seems that the shared library is loaded but incorrectly because:

root [0] .L readData.C
root [1] readData()
0 : successfully loaded
Number of entries = 9999
0 Charge = 140.125, Amplitude = 20.3438
1 Charge = 136.727, Amplitude = 22.0606
2 Charge = 302, Amplitude = 41.5
3 Charge = 131.5, Amplitude = 22.375
4 Charge = 147.125, Amplitude = 21.0938
5 Charge = 157.545, Amplitude = 23.1818
208 Charge = 144.688, Amplitude = 22.9062
209 Charge = 148.364, Amplitude = 23.4545
Error: Symbol #include is not defined in current scope  readData.C:75:
Error: Symbol exception is not defined in current scope  readData.C:75:
Syntax Error: #include <exception> readData.C:75:
Error: Symbol G__exception is not defined in current scope  readData.C:75:
Error: type G__exception not defined FILE:/eth/ethraid5/home/dnarrias/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysiscam/analysisDataTrcFiles/./readData.C LINE:75
*** Interpreter error recovered ***

I have no idea what the error message means. I’m puzzled, I don’t know what’s going on and how I could fix it. I attach the readData.C (which shouldn’t be the source of the problem) and the file (compiled in a 32bit platform). Perhaps is the problem and the Makefiles consequently?

Hope somebody has any clue to solve this. Thanks in advance!!

P.S: To download .so: … NTSjg/edit
readData.C (3.67 KB)

Your “readData.C” is missing something like:
#include “hit.h”
#include "event.h"
After adding appropriate #include lines, try (watch any warning and/or error messages from the compiler):
root [0] gSystem->Load(“”);
root [1] .L readData.C++

What concerns undefined “G__exception” problem, try to re-run your macro with CINT’s “exception catching” switched on:
root [0] .except
root [1] .L readData.C
root [2] readData()

Both solutions worked perfectly!!! :slight_smile:

The ‘G_exception’ problem was due to a ‘std::out_of_range’ in the hit vector in the entry 210. Now it’s solved!!

Thank you very much!!!