TMatrixT<long double>

Hello, I would like to perform some matrix calculations with matrices that have higher precision than double, and am trying to use TMatrixT. When I compile it into a shared library (with gcc) I don’t get any compilation errors, but when I then try to compile an executable with that library linked to it I get a bunch of “undefined reference” errors.

How do I need to link everything so that I can use TMatrixT? I presume that it’s tricky because the TMatrixT template code is split between the .h and .cxx files. I’ve tried compiling a dictionary with a LinkDef.h similar to that found in $ROOTSYS/math/matrix/inc/LinkDef.h, but to no avail.

Thanks!

ROOT Version: 5.32/01
Linux RHEL5, x86-64, gcc 4.2.3

My.h

#include "TMatrixT.h"
class MyClass
{
  public:
    TMatrixT<long double> MyMatrix;
};

Sample Error:
undefined reference to `TMatrixTBase::Shift(int, int)’

Hi Paul,

You only have to make changes in the inc directory.

Carefully follow an example like TMatrixD. You will notice that you
forgot to define TMatrixTBase for your type. That is the one that contains
Shift.

  • Eddy

Thank you for the reply! I guess I should have been more specific about my situation:

I’m making this code for my collaboration, and they don’t want to have to modify any of the ROOT distribution files. This makes it much trickier! Also note that there are many, many, many more error messages than the one I included above (I’m sure you know this though).

The closest solution I’ve found so far is to create a new .cc file in my personal library, and in it: #include the .cxx files from the $ROOTSYS/math/matrix/src folder, and try to explicitly instantiate TMatrixT by adding lines similar to the template instantiation ones at the end of those .cxx files for TMatrixD, TVectorD, etc.

Unfortunately, while trying to eliminate the compiler errors from doing this I’ve come across one that I can’t undo: in TMatrixT::Streamer(TBuffer&), TBuffer::ReadArray is called on the matrix elements “fElements”. However, this ReadArray function has not been defined for long double input, and thus won’t compile. There may be other errors too, but this is as far as I got.

So it looks like it’s not possible (at the moment), even if the template code wasn’t split up amongst .cxx and .h files. Is there another solution, or is there any plan to support this in the future?

Sample code in new .cc file that is compiled into the library:

#include <TMatrixT.cxx>
#include <TMatrixTSym.cxx>
#include <TMatrixTBase.cxx>
//etc.

template class TMatrixT<long double>;

template TMatrixT<long double>  operator+  <long double>(const TMatrixT<long double>    &source1,const TMatrixT<long double>    &source2);
//etc.

I am not suggesting to modify any ROOT code.
You must have somewhere your own code. Just install there
some new include files, like TMatrixLDBase.h, TMatrixLD.h etc.
Install there too a LinkDef.h with the necessary info for the new class.