Can't call C++ code from Root macro

Hi there!
I’m pretty sure this is an obvious error on my behalf, but I can’t figure it out for the life of me. Searching the forums didn’t do any good either. Anway, here goes:

I’m trying to diagonalise a matrix. So I’ve set up a ROOT macro to read the data and call J-P Moreau’s algorithm, provided as a C++ source file and some headers. My (not working) minimal example is as follows:

The Root macro, located in QLtest.c:[code]#include “vmblock.h”

void QLtest() {

gROOT->ProcessLine(".L vmblock.cxx+");

void *vmblock = NULL;
int N = 4;
// allocate memory for matrix A and vectors B, X, D (index 0 not used)
vmblock = vminit();
Z = (REAL **) vmalloc(vmblock, MATRIX, N+1, N+1);
D = (REAL *) vmalloc(vmblock, VEKTOR, N+1, 0);
E = (REAL *) vmalloc(vmblock, VEKTOR, N+1, 0);

if (! vmcomplete(vmblock))
LogError (“No Memory”, 0, FILE, LINE);

// define input symmetric matrix
Z[1][1]= 4.0; Z[1][2]=-2.0; Z[1][3]=-1.0; Z[1][4]= 0.0;
Z[2][1]=-2.0; Z[2][2]= 4.0; Z[2][3]= 0.0; Z[2][4]=-1.0;
Z[3][1]=-1.0; Z[3][2]= 0.0; Z[3][3]= 4.0; Z[3][4]=-2.0;
Z[4][1]= 0.0; Z[4][2]=-1.0; Z[4][3]=-2.0; Z[4][4]= 4.0;

Running ‘root -l QLtest.c’ yields Error: vminit() header declared but not defined QLtest.c:10:This error can be cured by removing the #include “vmblock.h”, but if I do so, I lose the MATRIX and all kind of other defines (still, the vminit() works in this case). So what am I doing wrong? Any advice is greatly appreciated.
This is root ROOT 5.18/00b (branches/v5-18-00-patches@22563 running on ubuntu (10.04, IIRC).
Best wishes,


Relevant parts of the algorithm, located in vmblock.cxx:[code]#include <malloc.h>

#include “basis.h”
#include “vmblock.h”

typedef struct VML /* Element of a vector/matrix list */
void vmzeiger; / pointer to the vector or matrix /
int typ; /
kind of pointer: vector or matrix /
(possible values: VEKTOR, VVEKTOR, /
size_t groesse; /
in the anchor element: the flag that /
indicates failed memory allocations; /
otherwise not used except for matrices /
where `groesse’ is “abused” to save /
the number of rows /
size_t spalten; /
number of columns of matrices of /
points in R3 */
struct VML naechst; / pointer to next element in the list */
} vmltyp;

#define VMALLOC (vmltyp )malloc(sizeof(vmltyp)) / allocate memory /
for a new /
element of the /
list */

#define LISTE ((vmltyp )vmblock) / for abbreviation /
#define MAGIC 410 /
used to mark a /
valid anchor /
element */


void vminit / create an empty vector/matrix list …/
) /
address of list …*/

vmltyp liste; / pointer to anchor element of list */

if ((liste = VMALLOC) == NULL) /* allocate memory for the anchor /
return NULL; /
unsuccessful? => report error /
liste->vmzeiger = NULL; /
to make vmfree() error free /
liste->typ = MAGIC; /
mark a valid anchor element /
liste->groesse = 0; /
no lack of memory as yet /
liste->naechst = NULL; /
no next element */

return (void *)liste;

The header file included in the above code, located in vmblock.h:[code]#ifndef VMBLOCK_H_INCLUDED

#define VEKTOR 0 /* for a REAL vector /
#define VVEKTOR 1 /
for a vector with elements /
of given size /
#define MATRIX 2 /
for a REAL matrix /
#define IMATRIX 3 /
for an int matrix */

#define MMATRIX 4 /* for a matrix of 4x4 matrices /
(with elements of type `mat4x4’) /
#define UMATRIX 5 /
for a lower triangular matrix */

#define PMATRIX 6 /* for a matrix of points in R3 */

void vminit / create an empty vector/matrix list …/
); /
address of list …*/



Did you generate, compile and link a dictionary for the content of vmblock.h and vmblock.cxx? Did you load the resulting shared library?


Not voluntarily[1]. How would I do so?

[1] I created the .cxx and .h files and ran ‘root -l QLtest.c’, that’s all. So if I need to create this dictionary manually, the answer is ‘no’

Humm sorry, actually you did:#include "vmblock.h" void QLtest() { gROOT->ProcessLine(".L vmblock.cxx+"); which I missed at the last read. There is probably some confusion between the interpreted version (which your request in the first line) and the compiled version (which you request on the last line). To avoid this confusion try the following:#ifdef __CINT__ #include "vmblock.cxx+" #else #include "vmblock.cxx" #endif void QLtest() {